'                   **LANDER**
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@    Coded By Christopher Rankine (C) in 2002     @
'@                                                 @
'@               LEFT to thrust left               @
'@              RIGHT to thrust right              @
'@                  X to thrust up                 @
'@-===============================================-@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

gosub setup
gosub title
gosub intro
gosub loop
exit

label intro
gosub intro_text
repeat
c=peek("port1")
if and(c,16384)>0 then
pause .5
return
fi
if and(c,1)>0 end
until (and(c,1)>0)
return

label intro_text
text 100,40, "The objective of the game is to land on the" 
text 100,60,"green platforms. Use your thrusters to move "
text 100,80, "through the dangerous red rock. Hit the "
text 100,100, "rock and you lose a continue. The yellow"
text 100,120, "block on each level fills up your fuel fast"
text 100,140, "while the blue blocks fill it up slowly."
text 100,160, "Don't waste too much time as there is a"
text 100,180, "time limit. You must land on a green "
text 100,200, "platform before the time runs out. If you"
text 100,220, "run out of fuel or crash you will start back"
text 100,240, "over a yellow block. If you run out of time"
text 100,260, "it is game over."
text 100,280, "Complete each level to get more time."
text 100,300, "If you complete the game you will be told"
text 100,320, "how long it took you."
text 100,340, "How fast can you do it?"
text 100,380, "Press X to begin"
return


label title
text 220,200, "Christopher Rankine"
pause 2
clear window
text 270,200, "Presents"
pause 1 
clear window
text 230,200, "A Lab Production"
pause 1
clear window
text 270,200, "Lander"
pause 2 
clear window
return

label setup
REM Set up variables and arrays
open window 640,512
plx=305                            REM Player's x-position
ply=100                            REM Player's y-position
ground=512                         REM Ground position
fuel=100                           REM Player's fuel
cont=10                            REM No. of continues
game_timer=0                       
level_timer=3000
dim platforms (10,16)              REM set up level
lev=1                              REM FIRST LEVEL = 1

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''         LOADS UP DATA FOR CURRENT LEVEL              ''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
label level_setup
if lev=1 restore level1
if lev=2 restore level2
if lev=3 restore level3
if lev=4 restore level4
for y = 1 to 16
for x = 1 to 10
if lev <5 then 
read platforms(x,y)
fi
if lev=5 then    REM If level 4 is completed then end 
close window
goto complete
fi
next x
next y
return


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''                    DEATH MESSAGE                     ''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
label death
open window 640,512
beep
repeat
c=peek("port1")
setrgb 1, 100, 0, 0
fill circle ran(640), ran(512), ran(25)
setrgb 1, 125, 125, 125
text 200,226, "You are dead! Press select to end"
until (and(c,1)<>0)
return


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''                 COMPLETE MESSAGE                     ''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
label complete
open window 640,512
beep
text 200,256, "You won! Press select to end"
text 100,226, "It took you " + str$(int(game_timer/50)) + " seconds to win"
repeat
c=peek("port1")
setrgb 1, 125, 125, 125
until (and(c,1)<>0)

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''                        MAIN LOOP                     ''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
label loop
repeat
c=peek("port1")
setdrawbuf d
d=1-d
setdispbuf d
clear window
gosub level
gosub ship
gosub thrust
gosub fuel
gosub level_status
gosub timers
text 40,40, str$(lev)
text 40,60, str$(int(level_timer/50))
until ((and(c,1)>0) or (lev=5) or (dest=1))
return

label timers
if lev<5 then
game_timer=game_timer+1
fi
if lev<5 then
level_timer=level_timer-1
fi
if level_timer=0 then
dest=1
close window
gosub death
fi
return

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''         IF LEVEL IS COMPLETE THEN CHANGE LEVEL       ''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
label level_status
if lev_complete=1 then
lev=lev+1
lev_complete=0
level_timer=3000
gosub level_setup
plx=305
ply=100
fi
return

label fuel
if fuel>100 fuel=100
setrgb 1, 255, 255, 255
text 30,500, "fuel"
IF (fuel>75) then
setrgb 1, 0, 255,0
fi
if (fuel<=75) then
setrgb 1, 255, 255,0
fi
if (fuel<50 ) then
setrgb 1, 255, 100,0
fi
IF (fuel<25) then
setrgb 1, 255, 0,0
fi
fill rectangle 100,490 to 100+(fuel*2),506
rectangle 100, 490 to 300, 506
return

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''   DRAW SHIP AND SET UP COLLISION WITH PLATFORMS      ''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
label ship
bx=int(plx/64)+1 REM bottom collision
by=int(ply/32)+1

rx=int((plx+10)/64)+1 REM right collision
ry=int((ply-40)/32)+1

lx=int((plx-10)/64)+1 REM left collision
ly=int((ply-40)/32)+1

tx=int((plx)/64)+1 REM top collision
ty=int((ply-50)/32)+1

setrgb 1,100,100,100
fill triangle plx-10,ply-40 to plx+10,ply-40 to plx,ply-50
fill rect plx-10,ply-40 to plx+10,ply

REM IF ABOVE GROUND ADD ON GRAVITY TO SHIP Y POSITION
if ply<ground then
ply=ply+grav
grav=grav+0.1
fi

if grav>5 grav=10

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''          COLLISION BETWEEN SHIP AND PLATFORMS        ''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
REM IF ROCK IS HIT LOSE A CONTINUE AND GO BACK TO START
if platforms(tx,ty)=2 and grav>=0 then
cont=cont-1
plx=305
ply=100
grav=0
wait 1
fi

if platforms(rx,ry)=2 and grav>=0 then
cont=cont-1
plx=305
ply=100
grav=0
wait 1
fi

if platforms(lx,ly)=2 and grav>=0 then
cont=cont-1
plx=305
ply=100
grav=0
wait 1
fi

if platforms(bx,by)=2 and grav>=0 then
cont=cont-1
plx=305
ply=100
grav=0
wait 1
fi

REM IF SLOW POWER UP IS HIT GAIN FUEL SLOWLY
if platforms(bx,by)=3 and grav>=0 then
ply=(by-1)*32
fuel=fuel+0.1
fi
REM IF FAST POWER UP IS HIT GAIN FUEL FAST
if platforms(bx,by)=4 and grav>=0 then
ply=(by-1)*32
fuel=fuel+0.2
fi

REM IF LANDING PLATFORM IS HIT THEN LAND
if platforms(bx,by)=1 and grav>=0 then
ply=(by-1)*32
grav=0
lev_complete=1
fi
REM IF NO CONTINUES LEFT GO TO DEATH MESSAGE
if cont=0 then
dest=1
close window
gosub death
fi
REM SCREEN BOUNDARIES
if ply<60 ply=60
if plx>620 plx=620
if plx<20 plx=20
return


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' BURN FUEL TO MOVE SHIP AROUND SCREEN AND DRAW FLAME  ''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
label thrust

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''                     SET UP FLAME                     ''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
fc=ran(255)  
sv=sv+.1
wv=3+3*sin(sv)

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''           IF X IS PRESSED GO UP AND BURN FUEL        ''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
c=peek("port1")
if and(c,16384)>0 and (fuel>0) then
grav=-1
fuel=fuel-.1
setrgb 1,250,fc,0
fill rectangle plx-7,ply+10+wv to plx-1,ply
fill rectangle plx+7,ply+10+wv to plx+1,ply
fi

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''   IF LEFT IS PRESSED GO LEFT UP AND BURN FUEL        ''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
if and(c,128)>0  and (fuel>0) then
plx=plx-1
grav=.1
fuel=fuel-.1
setrgb 1,250,fc,0
fill rectangle plx+10,ply-40+wv to plx+25,ply-30
fi

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''   IF RIGHT IS PRESSED GO RIGHT UP AND BURN FUEL      ''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
if and(c,32)>0 and (fuel>0) then
plx=plx+1
grav=.1
fuel=fuel-.1
setrgb 1,250,fc,0
fill rectangle plx-10,ply-40+wv to plx-25,ply-30
fi
return

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''                       DRAW LEVEL                     ''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
label level
  setrgb 1,0,0,50
  setrgb 2,50,50,100
  setrgb 3,30,30,100
   gtriangle 0,0 to 640,512 to 0,512
   setrgb 3,0,0,50
   gtriangle 0,0 to 640,512 to 640,0
drawy=0 
for y = 1 to 16
drawx=0
for x = 1 to 10
if platforms(x,y)=0 goto out
  if platforms (x,y) = 1 then
   setrgb 1,10,175,10
   fill rectangle drawx+2,drawy to drawx+64,drawy+30
   setrgb 1,40,125,40
   fill rectangle drawx+2,drawy+2 to drawx+62,drawy+30
  fi
  if platforms (x,y) = 2 then
   setrgb 1,100,17,10
   fill rectangle drawx+2,drawy to drawx+65,drawy+32
   setrgb 1,140,12,40
   fill rectangle drawx+2,drawy+2 to drawx+62,drawy+30
  fi
  if platforms (x,y) = 3 then
   setrgb 1,100,17,200
   fill rectangle drawx+2,drawy to drawx+65,drawy+32
   setrgb 1,14,12,100
   fill rectangle drawx+2,drawy+2 to drawx+62,drawy+30
  fi
  if platforms (x,y) = 4 then
   setrgb 1,100,170,20
   fill rectangle drawx+2,drawy to drawx+65,drawy+32
   setrgb 1,140,120,10
   fill rectangle drawx+2,drawy+2 to drawx+62,drawy+30
  fi

label out
  drawx=drawx+64
next x
drawy=drawy+32
next y
return

REM 1=landing platform 
REM 2=destroy platform
REM 3=Slow fuel power up 
REM 4=Faster fuel power up 

label level1
data 0,0,0,0,0,0,0,2,2,2
data 2,2,2,0,0,0,0,2,2,2
data 2,0,0,0,0,0,0,0,0,0
data 2,0,0,0,0,0,0,0,0,0
data 2,0,2,0,0,0,0,2,2,0
data 2,0,2,2,0,2,2,2,2,0
data 2,0,2,2,0,2,2,2,2,0
data 2,0,2,2,0,0,2,0,2,0
data 2,0,2,2,0,0,0,0,2,0
data 2,0,0,2,0,0,0,0,2,0
data 2,0,0,2,0,2,2,0,2,0
data 2,2,0,2,0,2,2,0,2,0
data 2,2,0,2,0,2,2,0,2,0
data 2,0,0,2,0,2,2,0,2,0
data 2,0,0,2,0,2,2,0,2,0
data 2,1,2,2,4,2,2,1,2,1

label level2
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 2,2,0,2,4,2,0,2,2,2
data 0,0,0,2,2,2,0,2,2,2
data 0,0,0,2,2,2,0,2,0,0
data 0,2,2,2,2,2,0,2,0,0
data 0,2,2,2,2,2,0,2,0,1
data 0,0,0,0,2,2,0,0,0,2
data 0,0,0,0,2,2,0,0,0,2
data 2,2,2,0,2,2,2,2,2,2
data 0,0,0,0,2,2,2,2,2,2
data 0,0,0,0,2,2,2,2,2,2
data 1,2,2,2,2,2,2,2,2,2

label level3
data 0,0,0,0,0,0,0,2,0,0
data 0,0,0,0,0,0,0,2,0,0
data 0,0,0,0,0,0,0,2,0,1
data 0,0,0,0,0,0,0,2,0,2
data 2,0,2,2,4,2,2,2,0,0
data 2,0,2,0,0,0,2,2,0,0
data 2,0,0,0,0,0,2,2,2,0
data 2,0,0,0,2,0,0,0,2,0
data 2,0,0,2,2,0,0,0,2,0
data 2,0,0,2,2,2,3,0,2,0
data 2,3,2,2,2,2,2,0,2,0
data 2,2,2,2,2,2,2,0,2,0
data 2,2,2,2,2,2,2,0,2,0
data 2,2,2,2,2,2,2,0,0,0
data 2,2,2,2,2,2,2,0,0,0
data 2,2,2,2,2,2,2,2,2,3

label level4
data 0,0,0,0,0,0,0,2,2,2
data 0,0,0,0,0,0,0,2,2,2
data 0,0,0,0,0,0,0,2,2,2
data 0,0,0,0,0,0,0,2,2,2
data 2,0,2,2,4,2,2,2,0,0
data 2,0,2,2,0,0,0,2,0,0
data 2,0,2,2,0,0,0,2,1,0
data 2,0,2,2,0,2,0,0,2,0
data 2,0,0,2,0,2,0,0,2,0
data 2,0,0,2,0,2,3,0,2,0
data 2,3,0,2,0,2,2,0,2,0
data 2,2,0,2,0,2,2,0,2,0
data 2,2,0,2,0,2,2,0,2,0
data 2,2,0,0,0,2,2,0,0,0
data 2,2,0,0,0,2,2,0,0,0
data 2,2,2,2,2,2,2,2,2,3







