You have to land before you run out of fuel. When you land perfectly you get 100 points.
When you crash or run out of fuel you lose a ship. Also I added legs to the spacecraft.
You only use fuel when you use the rocket engines.
Code: Select all
' gravity test program by neil
Screenres 640,480,32,,1 'fullscreen
'Screenres 640,480 'small screen
Dim As ULong fps,wht,ylw,sc
Dim AS UByte en,shp
Dim AS Single x, y, vx, vy, fuel
Dim As String key
ylw = rgb(255,255,0)
wht = rgb(255,255,255)
setmouse 0,0,0
Function Regulate(Byval MyFps As Long,Byref fps As Long) As Long
Static As Double timervalue,_lastsleeptime,t3,frames
frames+=1
If (Timer-t3)>=1 Then t3=Timer:fps=frames:frames=0
Var sleeptime=_lastsleeptime+((1/myfps)-Timer+timervalue)*1000
If sleeptime<1 Then sleeptime=1
_lastsleeptime=sleeptime
timervalue=Timer
Return sleeptime
End Function
start:
sc = 0:shp = 5
resume_game:
x = 320 ' Initial x position
y = 40 ' Initial y position
vx = .05 ' Initial x velocity
vy = .05 ' Initial y velocity
fuel = 1000 ' Initial fuel level
en = 0
DO
Screenlock
Cls
' Draw the lander
CIRCLE (x, y), 10, ylw ' Draw the body
LINE (x - 12, y + 10)-(x + 12, y + 10), ylw ' the lander bar
LINE (x - 10, y + 10)-(x + 15, y + 20), ylw ' the lander leg
LINE (x - 15, y + 20)-(x + 10, y + 10), ylw ' the lander leg
LINE (10 - 10, 400 + 10)-(540 + 100, 400 + 10), wht ' Moonscape
' Display fuel level
locate 2,2:Print "Score ";sc
locate 2,35:print "Fuel: "; fuel
locate 2,70:Print "Ships = ";shp
'locate 4,1:print "gravity = .005"
'locate 6,1:print "Y Velocity = ";vy
'locate 8,1:print "X Velocity = ";vx
'locate 10,1:print "X Coordinate= ";x
'locate 12,1:print "Y Coordinate = ";y
'locate 14,1:print "FPS = ";fps
Screenunlock
' Update lander position based on velocity
x += vx
y += vy
' Apply gravity
vy += .005
if fuel > 0 Then
' Move space ship with arrow keys
IF multikey(&H4B) and multikey(&H4D) = 0 THEN vx -= .05:fuel -= 2 ' Move left
IF multikey(&H4D) and multikey(&H4B) = 0 THEN vx += .05:fuel -= 2 ' Move right
IF multikey(&H48) and multikey(&H50) = 0 THEN vy = vy - .05:fuel -= 5 ' Move up
if fuel <= 0 Then fuel = 0
End If
key = Inkey
' Check for collision with the ground
if x < -100 or x > 700 or y < -50 Then y = 393
IF y > 392 THEN
Locate 8,35: PRINT "Crash!"
shp -= 1
locate 2,70:Print "Ships = ";shp
SLEEP 2000,1
if shp = 0 Then
Locate 14,33:Print "Game Over!"
Locate 20,20:Print "Press (Y) To Play again or (N) to Quit!"
DO
if Multikey(&H15) Then Goto start
if Multikey(&H31) Then End
sleep 10,1
Loop until multikey(&H01)
en = 1
End If
if en = 1 Then End
goto resume_game
END IF
' Check for successful landing
IF vy <= 0 AND ABS(vx) <= 2 AND y >= 386 THEN
Locate 8,30: PRINT "Landing successful!"
sc += 100
locate 2,2:Print "Score ";sc
SLEEP 3000,1
goto resume_game
END IF
' set at 60 fps lower number to slow down
Sleep regulate(60,fps),1
Loop Until (key = Chr(27)) Or (key = Chr(255) & "k")