Sync On:Sync Rate 60:Autocam Off
SET DISPLAY MODE 1024, 768, 32
 
Type Coordinates
   x as Float
   y as Float
   z as Float
Endtype
 
Global Object as Coordinates
Global Target as Coordinates
Global AI As Coordinates
Global Camera As Coordinates
 
Type Stats
   Move as Coordinates
   Speed as Float
   Rot as Float
Endtype
Dim Ship(2) as Stats
 
Sky_Sphere()
Make_Racer(11)
Dim Beacon(2)
Dim Start_Time(2)
Dim Lap(2)
Dim Best_Lap(2)
Dim TrailID(2)
 
Position Object 11,0,0,100
For i = 1 to 720
   Turn Object Right 11,.5
   Position_Sail(11)
   Set Object To Object Orientation 3,11
   Sync
Next i
Make_Stars()
Make_Course(11)
Make_Racer(13)
Position Object 12,50,0,100
Ink Rgb(255,255,255),0
 
For i = 1 to 2
   Beacon(i)=1
   start_time(i)=Timer()
   best_lap(i)=999999
   TrailID(i)=1
Next i
Do
   AI_Move(13)
   Move_Ship(11)
   Position_Sky(11)
   Pointer(11,100+Beacon(1))
   Move_Camera(11)
   Set Cursor 0,0
   For i = 1 to 2
      Position_Sail(9+i*2)
      Trail(9+i*2)
      d#=Get_Dist(9+i*2,100+beacon(i)):d=d#
      If d<50 Then Beacon(i)=Beacon(i)+1
      If Beacon(i)>4
         Beacon(i)=1
         lap(i)=Int(timer()-start_time(i))/1000
         If lap(i)<best_lap(i) Then best_lap(i)=lap(i)
         start_time(i)=timer()
      Endif
      Print "Ship ";i;":"
      Print "Beacon ";(beacon(i));" distance: ";d
      Print "Time: ";Int((timer()-start_time(i))/1000)
      Print "Best lap: ";best_lap(i)
      Print
   Next i
   Sync
Loop
 
Function Move_Ship(ObjectID)
   n=(ObjectID-9)/2
   Ship(n).Speed=(Upkey())*.05
   Ship(n).Rot=Ship(n).Rot+(RightKey()-LeftKey())*.02-((Ship(n).Rot>0)-(Ship(n).Rot<0))*.01
   If Abs(Ship(n).Rot)<.01 Then Ship(n).Rot=0
   If Abs(Ship(n).Rot)>10 Then Ship(n).Rot=10*((Ship(n).Rot>0)-(Ship(n).Rot<0))
   Turn Object Right ObjectID,Ship(n).Rot
   If Object Exist(2)=0 then Make_AI()
   Return_Object(ObjectID)
   Position Object 2,Object.x,Object.y,Object.z
   Set Object To Object Orientation 2,ObjectID
   Move Object 2,Ship(n).Speed
   Return_AI()
   mx#=AI.x-Object.x:mz#=AI.z-Object.z
   Ship(n).Move.x=Ship(n).Move.x+mx#-.01*((Ship(n).Move.x>0)-(Ship(n).Move.x<0))
   Ship(n).Move.z=Ship(n).Move.z+mz#-.01*((Ship(n).Move.z>0)-(Ship(n).Move.z<0))
   Position Object ObjectID,Object.x+Ship(n).Move.x,0,Object.z+Ship(n).Move.z
EndFunction
 
Function AI_Move(ObjectID)
   n=(ObjectID-9)/2
   If Object Exist(2)=0 then Make_AI()
   Return_Object(ObjectID)
   Position Object 2,Object.x,Object.y,Object.z
   Set Object To Object Orientation 2,ObjectID
   Move Object Right 2,25
   d1#=Get_Dist(ObjectID,100+beacon(n))
   d2#=Get_Dist(2,100+beacon(n))
   Move Object Left 2,50
   d3#=Get_Dist(2,100+beacon(n))
   If d2#<d1# Then Ship(n).Rot=Ship(n).Rot+.02-((Ship(n).Rot>0)-(Ship(n).Rot<0))*.01
   If d3#<d1# Then Ship(n).Rot=Ship(n).Rot-.02-((Ship(n).Rot>0)-(Ship(n).Rot<0))*.01
   Ship(n).Speed=0
   d1#=Get_Dist(ObjectID,100+beacon(n))
   Return_Object(ObjectID)
   Position Object 2,Object.x,Object.y,Object.z
   Set Object To Object Orientation 2,ObjectID
   Move Object 2,d1#
   d2#=Get_Dist(2,100+beacon(n))
   move#=sqrt(Ship(n).Move.x*Ship(n).Move.x+Ship(n).Move.z*Ship(n).Move.z)
   If d1#>d2# And d1#>move#*5 And Move#<5 Then Ship(n).Speed=.05
   If Abs(Ship(n).Rot)<.01 Then Ship(n).Rot=0
   If Abs(Ship(n).Rot)>4 Then Ship(n).Rot=4*((Ship(n).Rot>0)-(Ship(n).Rot<0))
   Turn Object Right ObjectID,Ship(n).Rot
   Return_Object(ObjectID)
   Position Object 2,Object.x,Object.y,Object.z
   Set Object To Object Orientation 2,ObjectID
   Move Object 2,Ship(n).Speed
   Return_AI()
   mx#=AI.x-Object.x:mz#=AI.z-Object.z
   Ship(n).Move.x=Ship(n).Move.x+mx#-.01*((Ship(n).Move.x>0)-(Ship(n).Move.x<0))
   Ship(n).Move.z=Ship(n).Move.z+mz#-.01*((Ship(n).Move.z>0)-(Ship(n).Move.z<0))
   Position Object ObjectID,Object.x+Ship(n).Move.x,0,Object.z+Ship(n).Move.z
EndFunction
 
Function Move_Camera(ObjectID)
   Return_Object(ObjectID)
   Position Object 2,Object.x,Object.y,Object.z
   Set Object to Object Orientation 2,ObjectID
   Move Object 2,-100
   Move Object Up 2,10
   Move Object Right 2,5
   Return_AI()
   Set Camera To Follow AI.x,AI.y,AI.z,5,0,4,6,0
   Point Camera Object.x,Object.y,Object.z
Endfunction
 
Function Get_Dist(Object1,Object2)
   Return_Object(Object1)
   Return_Target(Object2)
   dx#=Object.x-Target.x:dy#=Object.y-Target.y:dz#=Object.z-Target.z
   d#=sqrt(dx#*dx#+dy#*dy#+dz#*dz#)
EndFunction d#
 
 
Function Make_Course(ObjectID)
   Return_Object(ObjectID)
   For beacon=1 to 4
      Make Object Sphere 100+beacon,20
      ang=rnd(359)
      x=sin(ang)*2000+Object.x:z=cos(ang)*1000+Object.z
      Position Object 100+beacon,x,0,z
      Set Object Emissive 100+beacon,Rgb(255,255,255)
      Return_Object(100+beacon)
   Next Beacon
EndFunction
 
Function Make_Racer(ObjectID)
   If Object Exist(2) Then Delete Object 2
   If Object Exist(ObjectID) Then Delete Object ObjectID
   If Object Exist(ObjectID+1) Then Delete Object ObjectID+1
   Make Object Sphere ObjectID,.1,1,1
   Make Object Sphere 2,10,10,10
   Scale Object 2,100,60,100
   Make Mesh From Object 2,2
   Add Limb ObjectID,1,2
   Offset Limb ObjectID,1,0,0,25
   Delete Object 2
   Make Object Cylinder 2,1
   Scale Object 2,800,5000,400
   Pitch Object Down 2,90
   Fix Object Pivot 2
   Make Mesh From Object 2,2
   Add Limb ObjectID,2,2
   Delete Object 2
   Make Object Sphere 2,1,10,10
   Scale Object 2,850,400,2
   Make Mesh From Object 2,2
   Add Limb ObjectID,3,2
   Offset Limb ObjectID,3,0,0,-24.5
   Delete Object 2
   Make Object Cylinder 2,1
   Scale Object 2,200,400,200
   Roll Object Right 2,90
   Fix Object Pivot 2
   Make Mesh From Object 2,2
   Add Limb ObjectID,4,2
   Add Limb ObjectID,5,2
   Offset Limb ObjectID,4,5,0,0
   Offset Limb ObjectID,5,-5,0,0
   Delete Object 2
   Make Object Sphere 2,1
   Scale Object 2,300,300,300
   Make Mesh From Object 2,2
   Delete Object 2
   Make Object Cylinder 2,1
   Scale Limb 2,0,300,2000,300
   Add Limb 2,1,2
   Add Limb 2,2,2
   Offset Limb 2,1,0,10,0
   Offset Limb 2,2,0,-10,0
   Pitch Object Down 2,90
   Fix Object Pivot 2
   Make Mesh From Object 2,2
   Add Limb ObjectID,6,2
   Add Limb ObjectID,7,2
   Offset Limb ObjectID,6,8,0,0
   Offset Limb ObjectID,7,-8,0,0
   Delete Object 2
   Make Object Cylinder 2,1
   Scale Object 2,50,5000,50
   Pitch Object Up 2,6.5
   Fix Object Pivot 2
   Make Mesh From Object 2,2
   Add Limb ObjectID,8,2
   Offset Limb ObjectID,8,0,25,18
   Delete Object 2
   Make Object Triangle 2,0,2,0,0,5,4,0,2.1,0
   Make Mesh From Object 2,2
   Add Limb ObjectID,9,2
   Offset Limb ObjectID,9,0,0,-24
   Delete Object 2
   Make Object Cylinder 2,1
   Scale Object 2,800,400,400
   Pitch Object Down 2,110
   Fix Object Pivot 2
   Make Mesh From Object 2,2
   Add Limb ObjectID,10,2
   Offset Limb ObjectID,10,0,-1,25
   Delete Object 2
 
   Set Object Cull ObjectID,0
 
   Make Object Triangle ObjectID+1,0,5,20,0,50,15,0,5,-20
   Position Object ObjectID+1,0,0,100
   Set Object Cull ObjectID+1,0
 
   If Bitmap Exist(1) Then Delete Bitmap 1
   Create Bitmap 1,512,512
   Box 0,0,511,511,Rgb(120,120,110),Rgb(150,150,150),Rgb(80,80,80),Rgb(60,50,50)
   If Image Exist(ObjectID+1) then Delete Image ObjectID+1
   Get Image ObjectID+1,0,0,511,511,0
   Texture Object ObjectID+1,ObjectID+1
   `Set Sphere Mapping On ObjectID+1,ObjectID+1
   Set Object Emissive ObjectID+1,RGB(100,100,100)
   Set Alpha Mapping On ObjectID+1,70
 
   If Bitmap Exist(1) then Delete Bitmap 1
   Create Bitmap 1,512,512
   Ink Rgb(255,255,255),0
   Box 0,0,511,511
   Ink 0,0
   Box 181,70,331,256
   If Image Exist(ObjectID) Then Delete Image ObjectID
   Get Image ObjectID,0,0,511,511,1
   Texture Limb ObjectID,1,ObjectID
   Rotate Limb ObjectID,1,0,180,0
   Set Current Bitmap 0
   Delete Bitmap 1
EndFunction
 
Function Position_Sail(ObjectID)
   Return_Object(ObjectID)
   Position Object ObjectID+1,Object.x,Object.y,Object.z
   Set Object To Object Orientation ObjectID+1,ObjectID
EndFunction
 
Function Position_Sky(ObjectID)
   Return_Object(ObjectID)
   Position Object 3,Object.x,Object.y,Object.z
EndFunction
 
Function Sky_Sphere()
   Make Object Sphere 3,5000,50,50
   Set Object Cull 3,0
   If Bitmap Exist(1) Then Delete Bitmap 1
   Create Bitmap 1,1024,1024
   Ink 0,0
   Box 0,0,1023,1023
   For i = 1 to 2000+Rnd(1000)
      Ink Rgb(rnd(100)+155,rnd(100)+155,rnd(100)+155),0
      Dot Rnd(1023),Rnd(1023)
   Next i
   If Image Exist(3) then Delete Image 3
   Get Image 3,0,0,1023,1023,1
   Texture Object 3,3
   Set Object Emissive 3,RGB(128,128,128)
EndFunction
 
Function Make_Stars()
   For i = 1001 to 1500
      Make Object Sphere i,1,6,6
      Position Object i,Rnd(10000)-5000,Rnd(500)-200,Rnd(10000)-5000
      Set Object Emissive i,rgb(255,255,255)
      `Set Alpha Mapping On i,50
   Next i
EndFunction
 
Function Make_AI()
   If Object Exist(2) Then Delete Object 2
   Make Object Sphere 2,1,6,6
   Hide Object 2
EndFunction
 
 
Function Return_Object(ObjectID)
`If Object Exist (ObjectID)
   Object.x=Object Position X(ObjectID):Object.y=Object Position Y(ObjectID):Object.z=Object Position Z(ObjectID)
`Endif
Endfunction
 
` This function shortens the Object Postion X/Y/Z() functions.
Function Return_Target(TargetID)
`If Object Exist (TargetID)
   Target.x=Object Position X(TargetID):Target.y=Object Position Y(TargetID):Target.z=Object Position Z(TargetID)
`Endif
EndFunction
 
` This function shortens the Object Postion X/Y/Z() functions for object #2
Function Return_AI()
If Object Exist (2)
   AI.x=Object Position X(2):AI.y=Object Position Y(2):AI.z=Object Position Z(2)
Endif
EndFunction
 
` This function shortens the Camera Postion X/Y/Z() functions.
Function Return_Camera(CameraID)
Camera.x=Camera Position X(CameraID):Camera.y=Camera Position Y(CameraID):Camera.z=Camera Position Z(CameraID)
EndFunction
 
Function Pointer(ObjectID,TargetID)
   If SpaceKey()=0
      If Object Exist(5) Then Delete Object 5
      ExitFunction
   Endif
   If Object Exist(2)=0 Then Make_AI()
   Return_Object(ObjectID)
   Position Object 2,Object.x,Object.y,Object.z
   Set Object To Object Orientation 2,ObjectID
   Move Object 2,10
   Move Object Up 2,47.5
   If Object Exist(5) Then Delete Object 5
   Return_Target(TargetID)
   Return_AI()
   Make Object Triangle 5,AI.x,AI.y,AI.z,Target.x,Target.y,Target.z,AI.x,AI.y+.5,AI.z
   Color Object 5,rgb(255,0,0)
   Set Object Emissive 5,rgb(255,0,0)
   Set Object Cull 5,0
   Set Alpha Mapping On 5,90
EndFunction
 
Function Trail(ObjectID)
   n=(ObjectID-9)/2
   move#=sqrt(Ship(n).Move.x*Ship(n).Move.x+Ship(n).Move.z*Ship(n).Move.z)
   If move#<.05
      For i = 1 to 10
         obj=n*200+i
         If Object Exist(obj) Then Delete Object obj
      Next i
      ExitFunction
   Endif
   obj=n*200+TrailID(n)
   If Object Exist(obj) Then Delete Object obj
   Make Object Plain obj,move#+1.0,3
   Return_Object(ObjectID)
   Position Object obj,Object.x,Object.y,Object.z
   Set Object To Object Orientation obj,ObjectID
   Move object obj,-27
   Return_Object(obj)
   Point Object obj,Object.x+Ship(n).Move.x,0,Object.z+Ship(n).Move.z
   Turn Object Right obj,90
   Color Object obj,Rgb(255,0,0)
   Set Object Emissive obj,Rgb(255,0,0)
   Ghost Object On obj
   Set Object Cull obj,0
   Set Object Collision Off obj
   TrailID(n)=TrailID(n)+1
   If TrailID(n)>10 Then TrailID(n)=1
   For i = 1 to 10
      obj=n*200+i
      If Object Exist(obj)
         Scale Object obj,100,70,100
      Endif
   Next i
EndFunction