sync on
sync rate 60
autocam off
 
rem make the ground
make matrix 1,10000,10000,10,10
 
rem make a cube for the vehicle and set it's collision on
make object cube 1,50
position object 1,5000,25,5000
set object collision to boxes 1
 
rem make a bunch of cylinders to crash into and set their collision
for n = 2 to 50
   make object cylinder n,100
   position object n,rnd(9900),50,rnd(9900)
   color object n,rgb(rnd(255),rnd(255),rnd(255))
   set object collision to boxes n
next n
 
rem main loop
 
do
   gosub _move_cube
   gosub _bang
 
   sync
loop
 
 
 
 
rem procedures sub-routines -----------------------------------------------------
_move_cube:
 
   rem check if arrow keys are pressed and control speed of cube
   if upkey()=1 then inc speed
   if downkey()=1 then dec speed
   if speed >= 30 then speed=30
   if speed <= -30 then speed=-30
 
   rem slow down cube when accelerator not engaged
   if upkey()=0 and downkey()=0
      speed=speed*.99
   endif
 
   move object 1,speed
 
   rem turn vehicle
   if leftkey()=1 then ang=wrapvalue(object angle y(1)-5)
   if rightkey()=1 then ang=wrapvalue(object angle y(1)+5)
 
   yrotate object 1,ang
 
   rem follow vehicle with camera
   x#=object position x(1)
   y#=object position y(1)
   z#=object position z(1)
   cangy#=object angle y(1)
 
   set camera to follow x#,y#,z#,cangy#,300,100,10,1
 
return
`-----------------------------------------------------------------------------
_bang:
   rem find out which object has been collided with and move it
   bang = object collision(1,0)
   if bang > 0
      set object to object orientation bang,1
      move object bang,speed*30
   endif
return