sync on : sync rate 1000 : autocam off
make matrix 1,1000,1000,70,70
x1=0 : x2=70 : height=0 : amount=2
for x=x1 to x2 : set matrix height 1,x,x1,height : set matrix height 1,x,x2,height : set matrix height 1,x1,x,height : set matrix height 1,x2,x,height : next x
repeat
x1=x1+1 : x2=x2-1 : amount=amount+1 : height=height-amount
for x=x1 to x2 : set matrix height 1,x,x1,height : set matrix height 1,x,x2,height : set matrix height 1,x1,x,height : set matrix height 1,x2,x,height : next x
until x1=34 and x2=36
amount=amount+1 : height=height-amount
SET MATRIX HEIGHT 1,35,35,HEIGHT
update matrix 1
dim xpos#(1000)
dim ypos#(1000)
dim zpos#(1000)
dim xvel#(1000)
dim yvel#(1000)
dim zvel#(1000)
dim yang#(1000)
xpos=300 : zpos=300
do
mmx=wrapvalue(mmx+mousemovex())
mmy=wrapvalue(mmy+mousemovey())
rotate camera mmy,mmx,0
if upkey()=1 then move camera 3
if downkey()=1 then move camera -3
if rightkey()=1 then xpos=xpos+1
if leftkey()=1 then xpos=xpos-1
if mouseclick()=1 then zpos=zpos+1
if mouseclick()=2 then zpos=zpos-1
gosub fluids
sync
loop
 
fluids:
   ob=ob+1
   if ob=>1001 then ob=1
      if object exist(ob)=0
         make object sphere ob,5
         position object ob,xpos,1000,zpos
         color object ob,rgb(0,0,128)
      endif
   for o=1 to 1000
   if object exist(o)=1
      xpos#(o)=object position x(o)
      ypos#(o)=object position y(o)
      zpos#(o)=object position z(o)
      yAng#(o)=object angle y(o)
      ang#=yAng#(o)      : frontX#=newxvalue(xPos#(o),ang#,1.2)  : frontZ#=newzvalue(zPos#(o),ang#,1.2)
      ang#=yAng#(o)+180  : backX#=newxvalue(xPos#(o),ang#,1.2)   : backZ#=newzvalue(zPos#(o),ang#,1.2)
      ang#=yAng#(o)+90   : leftX#=newxvalue(xPos#(o),ang#,1.2)   : leftZ#=newzvalue(zPos#(o),ang#,1.2)
      ang#=yAng#(o)-90   : rightX#=newxvalue(xPos#(o),ang#,1.2)  : rightZ#=newzvalue(zPos#(o),ang#,1.2)
 
      frontHeight#=get ground height(1,frontX#,frontZ#)
      backHeight#=get ground height(1,backX#,backZ#)
      leftHeight#=get ground height(1,leftX#,leftZ#)
      rightHeight#=get ground height(1,rightX#,rightZ#)
 
      xMoveDist#=(backHeight#-frontHeight#)/30
      zMoveDist#=(leftHeight#-rightHeight#)/30
 
      xvel#(o)=xvel#(o)+newxvalue(0,yAng#(o),xMoveDist#)
      zvel#(o)=zvel#(o)+newzvalue(0,yAng#(o),xMoveDist#)
 
      xvel#(o)=xvel#(o)+newxvalue(0,yAng#(o)-90,zMoveDist#)
      zvel#(o)=zvel#(o)+newzvalue(0,yAng#(o)-90,zMoveDist#)
 
      xvel#(o)=xvel#(o)*0.80
      zvel#(o)=zvel#(o)*0.80
 
      xpos#(o)=xpos#(o)+xvel#(o)
      ypos#(o)=ypos#(o)+yvel#(o)
      if ypos#(o)<=get ground height(1,xpos#(o),zpos#(o))
         yvel#(o)=0
         ypos#(o)=get ground height(1,xpos#(o),zpos#(o))
      else
         yvel#(o)=yvel#(o)-0.05
      endif
      zpos#(o)=zpos#(o)+zvel#(o)
      position object o,xpos#(o),ypos#(o),zpos#(o)
   endif
   next o
return