`weather challenge
`by tone3e
`tornado in the sand
sync on
createTornadoTexture()
createMapTexture()
createMap()
dim particles(160,5)
height = 1
xseg=45
zseg=45
for i = 1 to 10
   for j = 1 to 16
      inc t
      make object cube t, rnd(5)+2
      texture object t, 1
      ghost object on t
      particles(t,2) = (i-1)*5
      particles(t,4) = rnd(360)
      particles(t,5) = (i-1)*2
   next j
next i
 
DO
 
   `particles
   for t = 1 to 160
      particles(t,4) = particles(t,4)+7
      a# = particles(t,4)
      dx# = x# + sin(a#)*particles(t,2)
      dz# = z# + cos(a#)*particles(t,2)
      particles(t,1) = curvevalue(dx#, particles(t,1), particles(t,5))
      particles(t,3) = curvevalue(dz#, particles(t,3), particles(t,5))
      position object t, particles(t,1), particles(t,2), particles(t,3)
   next t
 
   `matrix
   if x#<0 then x#=0 : if x#>1995 then x#=1995
   if z#<0 then z#=0 : if z#>1995 then z#=1995
 
   repeat
   if newx < X#/xseg then newx = newx + 1
   if newz < Z#/zseg then newz = newz + 1
   if (newx -1) = x#/xseg then newx = newx -1
   if (newz -1) = z#/zseg then newz = newz -1
   until (newx >= x#/xseg) and (newz>=z#/zseg)
   set matrix height 1,newx,newz,height
   height = height-1
   update matrix 1
 
 
   `camera movement
   position camera x#,70,z#-130
   point camera x#,0,z#
 
   `movement
   if upkey() then inc z#,3
   if downkey() then dec z#,3
   if rightkey() then inc x#,3
   if leftkey() then dec x#,3
 
   SYNC
LOOP
 
`functions
FUNCTION createTornadoTexture()
   FOR x = 1 TO 16
      FOR y = 1 TO 16
         transparent = RND(1)
         IF transparent
            ink 0,0
            DOT x,y
         ELSE
            ink RGB(100,100,100), 0
            DOT x,y
         ENDIF
      NEXT y
   NEXT x
 
   GET IMAGE 1,1,1,16,16
ENDFUNCTION
 
FUNCTION createMapTexture()
   FOR x = 1 TO 16
      FOR y = 1 TO 16
         ink RGB(150,rnd(20)+80,30),0
         DOT x,y
      NEXT y
   NEXT x
 
   GET IMAGE 2,1,1,16,16
ENDFUNCTION
 
 
FUNCTION createMap()
   MAKE MATRIX 1,2000,2000,45,45
   UPDATE MATRIX 1
   PREPARE MATRIX TEXTURE 1,2,1,1
ENDFUNCTION