`Space Race
sync rate 20:hide mouse:color backdrop 0:set display mode 1024,768,32
`fog on:fog distance 5000
 
`make the head
make object sphere 2,6
color object 2,RGB(132,168,253)
set object ambience 2,rgb(0,0,255)
 
`gooey death graphics
CREATE BITMAP 1,128,128
SET CURRENT BITMAP 1
FOR I=1 TO 64
   FOR J=1 TO 64
      IF RND(1)=1
         INK RGB(0,0,0),0
      ELSE
         INK RGB(0,0,200),0
      ENDIF
      BOX ((J*2)-2),((I*2)-2),(J*2),(I*2)
   NEXT J
NEXT I
BLUR BITMAP 1,6
GET IMAGE 2,1,1,128,128
SET CURRENT BITMAP 0
DELETE BITMAP 1
 
LAVA=2
MAKE MATRIX LAVA,200,5000,50,50
PREPARE MATRIX TEXTURE LAVA,2,1,1
SET MATRIX TEXTURE LAVA,1,1
SET MATRIX LAVA,0,0,1,1,1,1,1
 
DIM LAVASIN(50,50)
 
FOR I=1 TO 50
   FOR J=1 TO 50
      LAVASIN(I,J)=RND(360)
   NEXT J
NEXT I
 
`Create all variables
t=3
size=5
color=1
partcolor=1
bodylength=7
speed=0
nextob=87
 
`The body part making loop
for t=3 to bodylength
 
   `Make a body part
   make object sphere t,size
 
   `Color it
   color object t,RGB((20*color)+150,color*50,color*50)
   set object ambience t,RGB((20*color)+150,color*50,color*50)
   dec size:inc color
next t
 
`Make the walls for the track
make object box 10,1,200,25000
color object 10,RGB(255,0,0):set object ambience 10,RGB(255,0,0)
rotate object 10,0,180,0
make object box 11,1,200,25000
color object 11,RGB(255,0,0):set object ambience 11,RGB(255,0,0)
rotate object 11,0,180,0:position object 11,object position x(10)-150,0,0
make object box 12,200,1,25000
position object 12,object position x(10)-75,object position y(10)+100,0
color object 12,RGB(255,255,255):set object ambience 12,RGB(255,255,255)
 
position object 2,object position x(10)-75,0,0
POSITION MATRIX LAVA,object position x(10)-150,-100,0
 
`Create all of the obstacles
For x=15 to 215
   make object box x,rnd(50)+50,rnd(100)+50,rnd(100)+50
   color object x,RGB(50,200,50):set object ambience x,RGB(50,200,50)  `ghost object on x
   position object x,object position x(10)-rnd(150),object position y(10)-(rnd(200)-100),nextob
   inc nextob,150
Next x
 
` game loop
do
   distance2=int(object position z(2))
   `Control the way the head faces by moving the mouse
   yrotate object 2,object angle y(2)+ (mousemovex()/2)
   xrotate object 2,object angle x(2)+ (mousemovey()/2)
   if object angle x(2)<-90
      xrotate object 2,object angle x(2)-object angle x(2)
      xrotate object 2,-90
   endif
   if object angle x(2)>90
      xrotate object 2,object angle x(2)-object angle x(2)
      xrotate object 2,90
   endif
 
   `speed controls
   If speed < 10
      If upkey() = 1 then Inc speed
   Endif
   If speed > 0
      If downkey() = 1 then Dec speed
   Endif
 
   ` position the bits
   t=bodylength
   for a=4 to bodylength
      position object t,object position x(t-1),object position y(t-1),object position z(t-1)
      t=t-1
   next a
 
   `this want's to be outside the loop because the last body part has to be attatched to the head.
   position object 3, object position x(2),object position y(2),object position z(2)
 
   `move the head in the direction it's facing
   move object 2,speed
 
   `put the camera in the right place.
   set camera to follow object position x(2),object position y(2),object position z(2),object angle y(2),40,object position y(2),10,1
   point camera object position x(2),object position y(2),object position z(2)
 
   `Gooey death
   FOR I=1 TO 50
      FOR J=1 TO 50
         INC LAVASIN(I,J),2
         IF LAVASIN(I,J)>360 THEN LAVASIN(I,J)=0
         SET MATRIX HEIGHT LAVA,I,J,SIN(LAVASIN(I,J))*20
      NEXT J
   NEXT I
   UPDATE MATRIX LAVA
 
   `collision junk
   for a=10 to 12
      If object collision(2,a) then goto OUCH
   next a
   for b=15 to 215
      if object collision(2,b) then goto OUCH
   next b
   IF OBJECT POSITION Y(2)<=MATRIX POSITION Y(LAVA) then goto OUCH
 
   if camera position y() > object position y(12)
      hide object 12
   else
      show object 12
   endif
 
   ghost matrix on 2
 
   if object position z(2) > matrix position z(2)+2000
      POSITION MATRIX 2,object position x(10)-150,-100,matrix position z(2)+2000
   endif
 
   if object position z(2) > 20000 then goto HAPPYENDING
 
   distance=int(object position z(2))
   inc score,(distance-distance2)*speed
 
   `Text stuff
   set text size 20:ink RGB(255,255,255),0
   Text 10,10,"FPS      "+str$(screen fps())
   Text 10,22,"Speed    "+str$(speed)
   Text 10,34,"Distance "+str$(distance)
   Text 10,46,"Score    "+str$(score)
loop
 
OUCH:
do
ink RGB(255,255,255),0:set text size 40
center text 512,324,"YOU CRASHED AND BURNED"
loop
 
HAPPYENDING:
do
ink RGB(255,255,255),0:set text size 40
center text 512,324,"YOU MADE IT TO THE END.... WOO.... !!"
loop