Sync On:Sync Rate 60:Autocam Off: Set Camera Range .2,1000
Fog On: Fog Color Rgb(20,40,20):Fog Distance 20,300
 
Global Reload
Global ReloadTime = 20
Global Power = 10
Global Lymphs as Float
Global LymphTime as Integer
Global SpawnTime = 2000
Global Parts
Global Repair as Float
Global Beacons=2
Global BeaconTimer=500
Global Health as Float
Health = 100.0
Null=Make Vector3(1)
Null=Make Vector3(2)
 
Make_Terrain(64,64)
 
For i = 1 to 10
   MedKit = Make_Medkit()
   Position Object Medkit, 640,0,640
   Turn Object Right Medkit,Rnd(360)
   Move Object Medkit,Rnd(500)
   x=Object POsition X(Medkit)+5:z=Object Position Z(MedKit)
   y=Get Terrain Ground Height(1,x,z)
   Position Object Medkit,x,y+1.1,z
Next i
 
For i = 1 to 10
   Boost = Make_Reload_Boost()
   Position Object Boost, 640,0,640
   Turn Object Right Boost,Rnd(360)
   Move Object Boost,Rnd(500)
   x=Object Position X(Boost)+5:z=Object Position Z(Boost)
   y=Get Terrain Ground Height(1,x,z)
   Position Object Boost,x,y+1,z
Next i
 
 
 
 
Make_Ship()
y#=Get Terrain Ground Height(1,700,580)
Position Object 100,710,y#-3.0,590
Turn Object Left 100,135
Pitch Object Up 100,23
Roll Object Left 100,8
 
For i = 1 to 10
   Part = Make_ShipPart()
   Position Object Part, 640,0,640
   Turn Object Right Part,Rnd(360)
   Move Object Part,Rnd(500)
   x=Object Position X(Part)+5:z=Object Position Z(Part)
   y=Get Terrain Ground Height(1,x,z)+1.1
   Position Object Part,x,y,z
   Rotate Object Part,Rnd(20),Rnd(20),rnd(20)
Next i
 
Position Camera 640,0,640
 
For i = 1 to 100
   Enemy=Make_Enemy()
   x#=rnd(1280):z#=Rnd(1280)
   y#=Get Terrain Ground Height(1,x#,z#)
   Position Object Enemy,x#,y#+1.6,z#
Next i
 
Do
   Move_Camera()
   ny#=Get Terrain Ground Height(1,CamX,CamZ)+1.2
   Position Camera CamX,ny#,CamZ
   Move_Bullets()
   Shoot_Bullet()
   Move_Enemy()
   If LymphTime>0
      Dec LymphTime
   Endif
   If LymphTime=0
      LymphTime=1000
      If Lymphs>0
         Dec Lymphs
      Endif
   Endif
   If Lymphs=0 Then LymphTime=1000
   Health=Health-Lymphs/1000.0
   Check_Medkits()
   Check_Reload_Boosts()
   Check_ShipPart()
   Check_Ship()
   If Health <=0 or Repair >= 100 Then Exit
   Set Cursor 0,0
   Print "Lymphs: ";Lymphs
   Print "Health: ";Left$(Str$(Health),5)
   Print "Ship Parts: ";Parts;"/10"
   Print "Ship Repair: ";Left$(Str$(Repair),5);%
   Print
   Print "FPS: ";Screen FPS()
   Sync
Loop
 
r#=0
If Health<=0
   Do
      Set Cursor 0,0
      Print "Lymphs: ";Lymphs
      Print "Health: ";Left$(Str$(Health),5)
      Print "Ship Parts: ";Parts;"/10"
      Print "Ship Repair: ";Left$(Str$(Repair),5);%
      Print
      Print "You have died."
      Rotate Camera 20,r#,20
      r#=r#+.5
      Sync
   Loop
   End
Endif
 
Do
   Set Cursor 0,0
   Print "Lymphs: ";Lymphs
   Print "Health: ";Left$(Str$(Health),5)
   Print "Ship Parts: ";Parts;"/10"
   Print "Ship Repair: ";Left$(Str$(Repair),5);%
   Print
   Print "Congratulations! You have escaped the planet!"
   Sync
Loop
End
 
 
 
 
Function Move_Camera()
   SlowMe#=Lymphs/100.0
   Move#=Upkey()*.25-Downkey()*.1
   If Move#>0
      Move#=Move#-SlowMe#
      If Move#<0 then Move#=0
   Endif
   If Move#<0
      Move#=Move#+SlowMe#
      If Move#>0 Then Move#=0
   Endif
   Turn#=LeftKey()*3-RightKey()*3
   Turn Camera Left Turn#
   Move Camera Move#
   Limit_Camera()
EndFunction
 
Function Limit_Camera()
   If CamX<2 Then Position Camera 2,CamY,CamZ
   If CamX>Object Size X(1)-2 Then Position Camera Object Size X(1)-2,CamY,CamZ
   If CamZ<2 Then Position Camera CamX,CamY,2
   If CamZ>Object Size Z(1)-2 Then Position Camera CamX,CamY,Object Size Z(1)-2
Endfunction
 
Function Make_Ship()
   Ink Rgb(50,50,50),0
   Box 0,0,128,128
   Get Image 1,0,0,128,128,0
   Sprite 1,0,0,2
   For i = 1 to 20
      Size Sprite 1,rnd(10)+10,rnd(10)+10
      Set Sprite Diffuse 1,0,0,0
      Set Sprite Alpha 1,180
      x=rnd(122):y=rnd(122)
      off=rnd(2)+1
      Paste Sprite 1,x+off,y+off
      d=rnd(128)+100
      Set Sprite Diffuse 1,d,d,d
      Paste Sprite 1,x,y
   Next i
   For i = 1 to 3
      Splotch(128,64,1)
      Sprite 1,0,0,1
      Set Sprite Alpha 1,60
      Paste Sprite 1,0,0
   Next i
   Get Image 100,0,0,128,128,0
   Make Object Sphere 100,18
   Make Mesh From Object 1,100
   Delete Object 100
   Make Object Box 100,20,20,40
   Add Limb 100,1,1
   Offset Limb 100,1,0,0,20
   Texture Object 100,2
Endfunction
 
Function Make_Enemy()
   E=Get_Free_Enemy()
   If E<1 Then ExitFunction -1
   Make Object Sphere E,.2,6,6
   Make Mesh From Object 1,E
   Delete Object E
   Make Object Box E,.5,.1,.1
   Make Mesh From Object 2,E
   Delete Object E
   Make Object Cube E,1
   Color Object E,Rgb(0,0,60)
   Add Limb E,1,1
   Offset Limb E,1,-.5,.5,.5
   Color Limb E,1,Rgb(255,0,0)
   Add Limb E,2,1
   Offset Limb E,2,.5,.5,.5
   Color Limb E,2,Rgb(255,0,0)
   Add Limb E,3,2
   Offset Limb E,3,0,.8,0
   Color Limb E,3,Rgb(255,255,0)
   Set Object Ambience E,0
   Set Object Specular E,Rgb(150,150,150)
   Set Object Specular Power E,200
   Set Object Collision To Boxes E
Endfunction E
 
Function Move_Enemy()
   For i = 1001 to 2000
      If Object Exist(i)
         Set Object Collision On i
         Set Vector3 1,CamX - Limb Position X(i,1),CamY - Limb Position Y(i,1),CamZ - Limb Position Z(i,1)
         Set Vector3 2,CamX - Limb Position X(i,2),CamY - Limb Position Y(i,2),CamZ - Limb Position Z(i,2)
         Turn#=(Length Vector3(1)-Length Vector3(2))*(Factor+.2)
         If Turn#>2 Then Turn#=2
         If Turn#<-2 Then Turn#=-2
         If Rnd(Length Vector3(1)) > 80 Then Turn#=.5*((Int(i/2)*2=i)-(Int(i/2)*2<>i))
         Turn Object Right i,Turn#
         oldy#=Object Position Y(i)
         o1=Object Collision(i,0)
         Move Object i,.18
         o2=Object Collision(i,0)
         Killme=0
         If (o1>2000 and o1<3001)
            If Object Exist(o1)
               Delete Object o1
            Endif
            Scale Limb i,3,Limb Scale X(i,3)-Power,100,100
            If Limb Scale X(i,3)<10 Then Killme=1
         Endif
         If (o2>2000 and o2<3001)
            If Object Exist(o2)
               Delete Object o2
            Endif
            Scale Limb i,3,Limb Scale X(i,3)-Power,100,100
            If Limb Scale X(i,3)<10 Then Killme=1
         Endif
         dist#=Camera_Dist(i)
         if dist#<2.5
            Lymphs=Lymphs+1
            Killme=1
         Endif
         x#=Object Position X(i):z#=Object Position Z(i)
         y#=Get Terrain Ground Height(1,x#,z#)
         Move Object i,(oldy#-y#)*.025
         Position Object i,x#,y#+.55,z#
         If Object Position X(i)<2 Then Position Object i,2,Object Position Y(i),Object Position Z(i)
         If Object Position X(i)>Object Size X(1)-2 Then Position Object i,Object Size X(1)-2,Object Position Y(i),Object Position Z(i)
         If Object Position Z(i)<2 Then Position Object i,Object Position X(i),Object Position Y(i),2
         If Object Position Z(i)>Object Size Z(1)-2 Then Position Object i,Object Position X(i),Object Position Y(i),Object Size Z(1)-2
         Set Object Collision Off i
         If Killme=1 Then Delete Object i
      Endif
   Next i
   Dec SpawnTime
   If SpawnTime<1
      Enemy=Make_Enemy()
      If Enemy>0
         x#=rnd(1280):z#=Rnd(1280)
         Position Object Enemy,x#,0,z#
      Endif
      SpawnTime=1000
   Endif
Endfunction
 
Function Camera_Dist(ObjID)
   If Object Exist(ObjID)=0 Then ExitFunction 0.0
   Set Vector3 1,Object Position X(ObjID)-CamX,Object Position Y(ObjID)-CamY,Object Position Z(ObjID)-CamZ
   d#=Length Vector3(1)
Endfunction d#
 
 
Function Get_Free_Enemy()
   flag=0
   For i = 1001 to 1100
      If Object Exist(i)=0
         flag=1
         Exit
      Endif
   Next i
   If flag=0
      i=-1
   Endif
Endfunction i
 
 
 
 
 
Function Splotch(h,s,img)
   If Bitmap Exist(1) Then Delete Bitmap 1
   Create Bitmap 1,s*2+1,s*2+1
   Lock Pixels
   Ink 0,0
   Box 0,0,1+s*2,1+s*2
   c=rnd(7)+h-3
   Ink Rgb(c,c,c),0
   r=rnd(s/2)+s/4
   For i# = 0.0 to 360.0 step 2
      x=sin(i#)*r+s/2
      y=cos(i#)*r+s/2
      line s/2,s/2,x,y
      r=r+(rnd(2)-1)
      if r>s+15 then r=s+15
      m=s-15:If m<2 then m=2
      if r<m then r=m
   Next i#
   Unlock Pixels
   Get Image img,0,0,1+s*2,1+s*2
   Set Current Bitmap 0
   Delete Bitmap 1
Endfunction
 
Function Grass()
   Ink Rgb(0,130,0),0
   Box 0,0,511,511
   g=0
   For i = 101 to 110
      Splotch(180,30,i)
      Sprite i,0,0,i
   Next i
   Lock Pixels
   Do
      sprt=rnd(9)+101
      Size Sprite sprt,rnd(3)+1,Rnd(3)+1
      Set Sprite Alpha sprt,180
      Set Sprite Diffuse sprt,0,Rnd(50)+Rnd(50)+100,0
      Paste Sprite sprt,rnd(65),rnd(65)
      Dot rnd(70),Rnd(70),Rgb(0,Rnd(50)+100,0)
      g=g+1
      If rnd(2000)+1000<g Then Exit
   Loop
   Unlock Pixels
   Get Image 3,5,5,69,69,1
   For i = 101 to 110
      Splotch(rnd(80)+130,30,i)
      Sprite i,0,0,i
   Next i
   Lock Pixels
   Ink Rgb(0,90,0),0
   Box 0,0,511,511
   g=0
   Do
      sprt=rnd(9)+101
      Size Sprite sprt,rnd(10)+10,Rnd(10)+10
      Set Sprite Alpha sprt,64
      Set Sprite Diffuse sprt,0,50+Rnd(50)+Rnd(50)+rnd(50)+rnd(50),0
      Paste Sprite sprt,rnd(127),rnd(127)
      g=g+1
      If rnd(1000)+200<g Then Exit
   Loop
   Unlock Pixels
   For j = 1 to 3
      Splotch(rnd(80)+130,30,1)
      Sprite 1,0,0,1
      Set Sprite Diffuse 1,Rnd(10),Rnd(10),0
      Set Sprite Alpha 1,80
      Size Sprite 1,20,20
      Lock Pixels
      For i = 1 to 12
         Paste Sprite 1,63+i*2,66-i*2
      Next i
      Unlock Pixels
   Next j
   Get Image 4,0,0,128,128,0
   Delete Sprite 1
   For i = 101 to 110
      If Sprite Exist(i) Then Delete Sprite i
   Next i
Endfunction
 
Function Create_Heightmap(x,y)
   Ink rgb(150,150,150),0
   Box 0,0,x,y
   s=(x/4)*(y/4)
   For i = 1 to s
      Randomize Timer()
      sx=rnd(x)
      sy=rnd(y)
      TileHeight=rnd(6)+rnd(6)+rnd(6)+rnd(6)+rnd(6)-(rnd(6)+rnd(6)+rnd(6)+rnd(6)+rnd(6))
      ss=rnd(8)+rnd(8)+rnd(8)+rnd(8)+8
      Splotch(TileHeight,ss,1)
      Sprite 1,0,0,1
      Set Sprite 1,0,1
      Set Sprite Alpha 1,rnd(55)+rnd(55)+rnd(55)
      Paste Sprite 1,sx,sy
   Next i
   c as dword
   for noise=1 to rnd(50)+rnd(50)+rnd(50)+50
      noisex=rnd(x)
      noisey=rnd(y)
      c=point(noisex,noisey)
      h=rgbr(c)+rnd(4)-rnd(4)
      ink rgb(h,h,h),0
      dot noisex,noisey
   Next noise
   shipx=x/2-3:shipy=y/2+3
   depth=0
   For i = 1 to 12
      Dot Shipx,ShipY,rgb(depth,depth,depth)
      Dot Shipx+1,ShipY,rgb(depth,depth,depth)
      depth=depth+8
      Shipx=Shipx+1
      Shipy=Shipy+1
   Next i
   if file exist("Heightmap.bmp") Then Delete File "Heightmap.bmp"
   Get Image 2,0,0,x,y,0
   Save Image "Heightmap.bmp",2
   If Sprite Exist(1) Then Delete Sprite 1
   Ink Rgb(255,255,255),0
   Print "Heightmap Done"
   Sync
Endfunction
 
 
Function Make_Terrain(x,y)
   Create_Heightmap(x,y)
   Grass()
   If Object Exist(1) then Delete Object 1
   Make Object Terrain 1
   Set Terrain Heightmap 1,"Heightmap.bmp"
   Set Terrain Texture 1,4,3
   Set Terrain Tiling 1,3
   Set Terrain Scale 1,20,.5,20
   Set Terrain Light 1,20,50,10,200,200,150,.2
   Build Terrain 1
   Set Object Collision Off 1
Endfunction
 
 
 
 
Function Shoot_Bullet()
   If Reload>0
      Dec Reload
      ExitFunction
   Endif
   If Mouseclick()<>1 Then Exitfunction
   Reload=ReloadTime
   B=Make_Bullet()
   If B<1 then Exitfunction
   Position Object B,CamX,CamY,CamZ
   Set Object To Camera Orientation B
   Move Object Right B,.2
   bx#=Object Position X(B):by#=Object Position Y(B):bz#=Object Position Z(B)
   Pick Screen MouseX(),MouseY(),1000
   Point Object B, CamX +Get Pick Vector X(), CamY +Get Pick Vector Y(), CamZ +Get Pick Vector Z()
   Move Object B,5
   Set Vector3 B,Object Position X(B)-bx#,Object Position Y(B)-CamY,Object Position Z(B)-bz#
Endfunction
 
 
Function Get_Free_Bullet()
   flag=0
   For i = 2001 to 3000
      If Object Exist(i)=0
         flag=1
         Exit
      Endif
   Next i
   If flag
      null=Make Vector3(i)
   Else
      i=-1
   Endif
Endfunction i
 
Function Make_Bullet()
   blt=Get_Free_Bullet()
   If blt=-1 Then ExitFunction -1
   Make Object Sphere blt,1,6,6
   Scale Object blt,25,25,500
   Set Object Collision To Boxes blt
Endfunction blt
 
Function Move_Bullets()
   For i = 2001 to 3000
      If Object Exist(i)
         Set Vector3 1,Object Position X(i)-CamX,Object Position Y(i)-CamY,Object Position Z(i)-CamZ
         If Length Vector3(1)>500 or Object Position Y(i)<0
            Delete Object i
         Else
            Position Object i,Object Position X(i)+X Vector3(i),Object Position Y(i)+Y Vector3(i),Object Position Z(i)+Z Vector3(i)
            Set Vector3 i,X Vector3(i),Y Vector3(i)-.01,Z Vector3(i)
         Endif
      Endif
   Next i
Endfunction
 
 
Function Make_Medkit()
   MedKit=Get_Free_Medkit()
   If MedKit< 1 Then ExitFunction -1
   Make Object Cube MedKit,1.8
   If Image Exist(10)=0
      Ink Rgb(0,0,255),0
      Box 0,0,32,32
      Ink Rgb(255,0,0),0
      Center Text 16,5,"+"
      Get Image 10,0,0,32,32,0
      Ink Rgb(255,255,255),0
   Endif
   Texture Object MedKit,10
   Set Object COllision Off MedKit
Endfunction MedKit
 
 
Function Get_Free_Medkit()
   Flag=0
   For i = 10 to 19
      If Object Exist(i)=0
         Flag=1
         Exit
      Endif
   Next i
   If Flag=0 then i=-1
Endfunction i
 
Function Check_Medkits()
   For i = 10 to 19
      If Object Exist(i)
         D#=Camera_Dist(i)
         if D#<3.5
            Delete Object i
            Health=Health+20
            If Health>100 Then Health=100
         Endif
      Endif
   Next i
Endfunction
 
Function Make_Reload_Boost()
   RB=Get_Reload_Boost()
   If RB< 1 Then ExitFunction -1
   Make Object Sphere RB,.8
   If Image Exist(20)=0
      Ink Rgb(0,0,0),0
      Box 0,0,32,32
      Ink Rgb(180,180,200),0
      Center Text 16,5,"B"
      Get Image 20,0,0,32,32,0
      Ink Rgb(255,255,255),0
   Endif
   Set Sphere Mapping On RB,20
   Set Object Collision Off RB
Endfunction RB
 
 
Function Get_Reload_Boost()
   Flag=0
   For i = 20 to 29
      If Object Exist(i)=0
         Flag=1
         Exit
      Endif
   Next i
   If Flag=0 then i=-1
Endfunction i
 
Function Check_Reload_Boosts()
   For i = 20 to 29
      If Object Exist(i)
         D#=Camera_Dist(i)
         if D#<3.5
            Delete Object i
            ReloadTime=ReloadTime-1
            If ReloadTime<1 Then ReloadTime=1
         Endif
      Endif
   Next i
Endfunction
 
 
Function Make_ShipPart()
   S=Get_ShipPart()
   If S< 1 Then ExitFunction -1
   Make Object Box S,2,2,4
   If Image Exist(30)=0
      Ink Rgb(200,200,200),0
      Box 0,0,32,32
      Ink Rgb(0,0,50),0
      Center Text 16,5,"S"
      Get Image 30,0,0,32,32,0
      Ink Rgb(255,255,255),0
   Endif
   Texture Object S,2
   Set Object Collision Off S
Endfunction S
 
 
Function Get_ShipPart()
   Flag=0
   For i = 30 to 39
      If Object Exist(i)=0
         Flag=1
         Exit
      Endif
   Next i
   If Flag=0 then i=-1
Endfunction i
 
Function Check_ShipPart()
   If Beacons>0 and BeaconTimer=500 and kb>0
      Dec BeaconTimer
      Dec Beacons
   Endif
   If BeaconTimer<1
      BeaconTimer=500
   Else
      If BeaconTimer<500
         Dec BeaconTimer
         If Object In Screen(100)
            Ink Rgb(255,0,0),0
            Center Text Object Screen X(100),Object Screen Y(100),"+"
            Ink Rgb(255,255,255),0
         Endif
      Endif
   Endif
   For i = 30 to 39
      If Object Exist(i)
         If BeaconTimer<500 And Object In Screen(i)<>0
            Ink Rgb(255,0,0),0
            Center Text Object Screen X(i),Object Screen Y(i),"*"
            Ink Rgb(255,255,255),0
         Endif
         D#=Camera_Dist(i)
         if D#<3.5
            Delete Object i
            Parts=Parts+1
         Endif
      Endif
   Next i
Endfunction
 
Function Check_Ship()
   i=100
   If Object Exist(i)
      D#=Camera_Dist(i)
      if D#<50 and Parts=10
         Repair=Repair+.01
      Endif
   Endif
Endfunction
 
#Constant CamX Camera Position X()
#Constant CamY Camera Position Y()
#Constant CamZ Camera Position Z()
#Constant Factor Rnd(1000.0)/1000.0
 
`keystate abreviations
#Constant k1 keystate(2)
#Constant k2 keystate(3)
#Constant k3 keystate(4)
#Constant k4 keystate(5)
#Constant k5 keystate(6)
#Constant k6 keystate(7)
#Constant k7 keystate(8)
#Constant k8 keystate(9)
#Constant k9 keystate(10)
#Constant k0 keystate(11)
#Constant ka keystate(30)
#Constant kb keystate(48)
#Constant kc keystate(46)
#Constant kd keystate(32)
#Constant ke keystate(18)
#Constant kf keystate(33)
#Constant kg keystate(34)
#Constant kh keystate(35)
#Constant ki keystate(23)
#Constant kj keystate(36)
#Constant kk keystate(37)
#Constant kl keystate(38)
#Constant km keystate(50)
#Constant kn keystate(49)
#Constant ko keystate(24)
#Constant kp keystate(25)
#Constant kq keystate(16)
#Constant kr keystate(19)
#Constant ks keystate(31)
#Constant kt keystate(20)
#Constant ku keystate(22)
#Constant kv keystate(47)
#Constant kw keystate(17)
#Constant kx keystate(45)
#Constant ky keystate(21)
#Constant kz keystate(44)