'                   **LAB HUNTER**
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@    Coded By Christopher Rankine (C) in 2002     @
'@                                                 @
'@                  UP to accelarate               @
'@                   DOWN to brake                 @
'@                     X to shoot                  @
'@-===============================================-@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

REM Lab Hunter
REM Coded by Christopher Rankine
REM A 2002 Lab Production
REM Completed on 11/6/02
REM Number of lines: 600
REM Check out yabasic.co.uk , yabasic.150m.com and
REM ps2-yabasic.co.uk for further yabasic code
REM Hi and thanks to Nick Simpson and Marc Gale

gosub setup
gosub main_loop
exit

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> Set up title screen          >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
label main_loop
repeat
c=peek("port1")
gosub tex
if and(c,16384)>0 gosub loop
until (and(c,1)>0)
return

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

label scroller
setrgb 1,255,255,0
text scx,scy, mid$(s$,p,67)
scx=scx-4
if scx<-10 then
scx=scx+10
p=p+1
if p>len(s$) p=0
fi
scy=480
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> MAIN GAME LOOP               >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
label loop
open window 640,512
repeat
c=peek("port1")
coll=coll+1
if coll>3 coll=1
gosub doublebuffer
gosub controller
gosub enemycars
gosub playercar
gosub bullets
gosub particles
gosub bombs
if coll=1 gosub carscollision
if coll=2 gosub bulletcollision
if coll=3 gosub bomb_collision
gosub score
gosub level
if enfiredelay>0 enfiredelay=enfiredelay-1
if firedelay>0 firedelay=firedelay-1
if energy<=0 then
close window
gosub death
kill=kill+1
fi
if distance>99999 then
close window 
gosub complete
com=com+1
fi
if time=0 then
close window 
gosub out_of_time
kill=kill+1
fi
until ((time<=0) or (distance>=100000) or (energy<=0))
REM Chech hi score and level and update title screen stats
if level>maxlev maxlev=level
if tscore>hi_score hi_score=tscore
tscore=0
score=0
gosub setup
close window
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> GAME OVER SCREENS            >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

label out_of_time
open window 640,512
beep
setrgb 1, 255, 255, 255
text 220,236,"You ran out of time."
text 240,256, "You are dead!"
wait 2
return

label complete
open window 640,512
beep
setrgb 1, 255, 255, 255
text 30,50,"Congratulations. You survived."
wait 2
return

label death
open window 640,512
beep
setrgb 1, 125, 125, 125
text 240,256, "You are dead!"
wait 2
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> SETUP VARIABLES AND ARRAYS   >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
label setup
liney=-60 : rem used for the white lines 
width=10 :rem The bigger the width the harder the game.
time=30*50 :rem 30 secconds
distance=0 : rem  Meters to travel.
plx=width+10 : rem set up player's x-position
ply=400 : rem set up player's y-position
mxbul=5 : rem maximum amount of bullets permitted.
encars=3 : rem Number of enemys
energy=150 : rem Your energy.
firedelay=1 : rem delay between player shots
enspeed=1 : rem speed enemy closes in on player
level=1 : rem current level
damage=10 : rem amount of damage enemy bombs cause
bomnum=50 : rem number used to check frequency of bombs
dim pbx(mxbul) : rem plaxer x bullet pos.
dim pby(mxbul) : rem player y bullet pos.
dim pbs(mxbul) : rem player bullet state.
dim x(encars) : rem enemy x pos.
dim y(encars) : rem enemy y pos.
dim c(encars) : rem enemy car state. 1= ok > 50=exploding.
bombs=1 : rem no. of bombs enemies drop
dim bx(bombs)
dim by(bombs)
dim bs(bombs)
particles=8 : rem no. of particles in explosions
dim partx(particles)
dim party(particles)
dim px(particles)
dim py(particles)
ptst=0
for a=1 to mxbul
pbs(a)=0
next a
for a=1 to encars
 c(a)=1
 y(a)=-40-(a-1)*100
 x(a)=width+ran(620-(width*2))
next a
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> CHANGE LEVELS AND INCREASE DIFFICULTY >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
label level
target_score=10*(level*2)
if score>target_score then
level=level+1
enspeed=enspeed+0.5
bomnum=bomnum-1
score=0
time=30*50
energy=100
width=width+20
damage=damage+(level)
distance=distance+11000
fi
REM Difficulty limits
if level>10 level=10
if width>150 width=150
if damage>35 damage=35
if enspeed>4 enspeed=4
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> ENEMY BOMBS                  >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
label bombs
for a = 1 to bombs
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> DRAW BOMBS  >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
if bs(a)=1 then
setrgb 1,ran(255),ran(255),ran(255)
fill rect bx(a)-3,by(a)-3 to bx(a)+3,by(a)+3
bx(a)=bx(a)
by(a)=by(a)+10
if by(a)>470 bs(a)=0
fi
next a
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> CAR EXPOSIONS!!!!            >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
label particles
if ptst=0 return
ptst=ptst-1
setrgb 1,ran(255),ran(255),0
for a=1 to particles
 fill rectangle px(a)-ran(4),py(a)-ran(4) to px(a)+ran(4),py(a)+ran(4)
 px(a)=px(a)+partx(a)
 py(a)=py(a)+party(a)
next a
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> PLAYER CAR - ENEMY BOMB COLLISION CHECKS >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
label bomb_collision
for a = 1 to bombs
if bs(a)=1 then
if by(a)+5>ply and by(a)<ply+32 then
if bx(a)+5>plx and bx(a)<plx+40 then
energy=energy-damage
bs(a)=0
fi
fi
fi
next a
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> ENEMY CAR - PLAYER BULLET COLLISION >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
label bulletcollision
for a=1 to mxbul
for b=1 to encars
if pbs(a)=1 and c(b)=1 then
  if pbx(a)>=x(b) and pbx(a)<=x(b)+29 and pby(a)>=y(b) and pby(a)<=y(b)+40 then
  pbs(a)=0
if ptst=0 then
for l=1 to particles
ptst=20
 partx(l)=-5+ran(10)
 party(l)=-5+ran(10)
 px(l)=pbx(a)
 py(l)=pby(a)
next l
fi
  r=int(ran(3/level))
  if r<1 then
  c(b)=50
  score=score+10
  tscore=tscore+10
  carkill=carkill+1
fi
  fi
fi
next b
next a
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> PLAYER BULLETS               >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
label bullets
for a=1 to mxbul
if pbs(a)=1 then
 setrgb 1,255,255,255
 fill rectangle pbx(a),pby(a) to pbx(a)+2,pby(a)+10
 setrgb 1,255,100+ran(155),0
 fill triangle pbx(a)-2,pby(a)+10 to pbx(a)+3,pby(a)+10 to pbx(a)+1,pby(a)+20+ran(10)
fi
pby(a)=pby(a)-10+(speed/4)
if pby(a)<=0 pbs(a)=0
next a
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> SET UP BULLETS TO FIRE!!!    >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
label fire
if firedelay>0 return
for a=1 to mxbul
if pbs(a)=0 then
pbx(a)=plx+14
pby(a)=ply
pbs(a)=1
firedelay=10
a=mxbul+1
fi
next a
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> ENEMY CAR - PLAYER CAR COLLISION >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
label carscollision
for a=1 to encars
if c(a)=1 then
 if y(a)>=ply-40 and y(a)<=ply+40 then
   if plx+1>x(a) and plx<=x(a)+29 and ply>y(a) and ply<=y(a)+40 then
  xm=(speed/2)
  speed=speed-(speed/10)
  c(a)=2
energy=energy-5
score=score+5
carkill=carkill+1
   fi
   if plx+30>=x(a) and plx+30<=x(a)+29 and ply>y(a) and ply<=y(a)+40 then
  xm=-(speed/2)
  speed=speed-(speed/10)
  c(a)=2
energy=energy-5
score=score+5
carkill=carkill+1
   fi
   if plx+1>x(a) and plx<=x(a)+29 and ply+40>y(a) and ply+40<=y(a)+40 then
  xm=(speed/2)
  speed=speed-(speed/10)
  c(a)=2
energy=energy-2
score=score+5
carkill=carkill+1
   fi
   if plx+30>=x(a) and plx+30<=x(a)+29 and ply+40>y(a) and ply+40<=y(a)+40 then
  xm=-(speed/2)
  speed=speed-(speed/10)
  c(a)=2
score=score+5
energy=energy-2
carkill=carkill+1
   fi
 fi
fi
next a
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> DISPLAY TIME LEFT, POINTS ETC >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
label score
setrgb 1, 255, 255, 255
text 420,50,"TIME LEFT: " + str$(int(time/50))
REM Energy bar
setrgb 1,0,0,0
fill rectangle 100, 490 to 300, 506
setrgb 1, 255, 255, 255
text 30,500, "Energy"
if energy>100 energy=100
if (energy>75) setrgb 1, 0, 255,0
if (energy<=75) setrgb 1, 255, 255,0
if (energy<50 ) setrgb 1, 255, 100,0
if (energy<25) setrgb 1, 255, 0,0
if energy>100 energy=100
fill rectangle 100,490 to 100+(energy*2),506

REM Distance bar
setrgb 1, 255, 255, 255
text 30,90, "Distance"
rectangle 120, 80 to 320,96
fill rectangle 120,80 to 120+(int(distance/1000)*2),96
if distance>100000 distance=100000

setrgb 1,210,210,250
text 30,25,"PLAYER SCORE: "+str$(score) 
text 30,45,"TARGET SCORE: "+str$(target_score)
text 30,65,"LEVEL: "+str$(level)

time=time-1
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> READ INPUT FROM PAD 1        >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
label controller
c=peek("port1")
if (and(c,32)<>0) xm=xm+.3
if (and(c,128)<>0) xm=xm-.3
if (and(c,16)<>0) speed=speed+.3
if (and(c,64)<>0) speed=speed-.2
if (and(c,16384)<>0) gosub fire
if speed>8 speed=8

if speed<1 speed=1
plx=plx+xm
ply=400-(speed*5)
if xm>0 then
xm=xm-.2
if xm<0 xm=0
fi
if xm<0 then
xm=xm+.2
if xm>0 xm=0
fi
if plx<width then
plx=width+speed
xm=0
energy=energy-1
fi
if xm>speed/2 xm=speed/2
if xm<-(speed/2) xm=-(speed/2)
if plx+31>(640-width) then
plx=((640-width))-32-speed
energy=energy-1
xm=0
fi
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> UPDATE SCREEN AND DRAW ROAD  >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
label doublebuffer
setdrawbuf dw
dw=1-dw
setdispbuf dw
setrgb 1,30,30,40
fill rectangle 0,0 to 640,512
setrgb 1,255,255,255
h=30
for a=liney to 520 step 60
fill rectangle 315,a to 325,a+30
next a
if level <=5 setrgb 1,40,80,40
if level >5 and level<=8 setrgb 1,100,80,20
if level >8 setrgb 1,100,100,100
fill rectangle 0,0 to width,512
fill rectangle 640,0 to 640-width,512
liney=liney+int(speed)
if liney>0 liney=liney-60
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> DRAW PLAYER CAR!!!           >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
label playercar
  setrgb 1,255,100,100
  setrgb 1,50,50,60
  fill rectangle plx-2,ply+4 to plx+32,ply+14
  fill rectangle plx-2,ply+28 to plx+32,ply+38
  setrgb 1,115,20,20
  fill rectangle plx,ply-5 to plx+30,ply+40
  setrgb 1,115,60,60
  fill rectangle plx+3,ply-5 to plx+27,ply+40
  setrgb 1,100,155,255
  fill rectangle plx+4,ply+7 to plx+26,ply+37
  setrgb 1,255,50,50
  fill rectangle plx+5,ply+10 to plx+25,ply+35
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> DRAW ENEMY CARS              >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
label enemycars
for a=1 to encars
if c(a)=1 then 
setrgb 1,55,55,120
fill rectangle x(a)+1,y(a) to x(a)+29,y(a)+40
setrgb 1,80,80,80
fill rectangle x(a)-1,y(a)+3 to x(a)+31,y(a)+14
fill rectangle x(a)-2,y(a)+26 to x(a)+32,y(a)+38
setrgb 1,70,70,170
fill rectangle x(a)+2,y(a) to x(a)+28,y(a)+40
setrgb 1,20,20,60
fill rectangle x(a)+1,y(a)+40 to x(a)+29,y(a)+35
setrgb 1,150,150,255
fill rectangle x(a)+3,y(a)+20 to x(a)+27,y(a)+35
setrgb 1,30,30,40
fill rectangle x(a)+3,y(a)+20 to x(a)+27,y(a)+12
fi

if c(a)>1 and c(a)<50 then
setrgb 1,255-c(a)*5,255-c(a)*5,0
 fill circle x(a)+15,y(a)+20,c(a)
 c(a)=c(a)+4
fi

REM MOVE ENEMY CARS ACCORDING TO PLAYER SPEED
y(a)=y(a)+1+(speed/2)-1

REM RESET CARS IF THEY ARE OFF SCREEN
if y(a)>512 then
 y(a)=y(a)-600
 x(a)=width+ran(620-(width*2))
 c(a)=1
carescape=carescape+1
fi
if (ply-speed)-y(a)<150 then
 if x(a)+32>plx+32 x(a)=x(a)-enspeed
 if x(a)<plx x(a)=x(a)+enspeed
fi
next a

REM SET UP ENEMY BOMBS
if enfiredelay=0 then 
for a=1 to encars
rnum=ran(bomnum)
if rnum<1 and c(a)=1 then 
if plx+32>x(a)-2 and plx-2<x(a)+32 then
if ply>y(a) then
for x = 1 to bombs
if bs(x)=0 then
  enfiredelay=10
  bx(x)=x(a)
  by(x)=y(a)
  bs(x)=1
  x=bombs+1
  a=enemy+1
fi
next x
fi
fi
fi
next a
fi
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> INTRODUCTORY TEXT            >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
label intro_text
open window 640,512
s$="                                                                 "
s$=s$+"Welcome to yet another exciting Lab Production "
s$=s$+"coded by Christopher Rankine (aka Doctor). " 
s$=s$+"The aim of the game is to reach your destination. "
s$=s$+"The journey is split across 10 levels where "
s$=s$+"you must destroy the enemy cars attempting to "
s$=s$+"stop you. You have to destroy enough cars in a "
s$=s$+"time limit to advance to the next level where the "
s$=s$+"game gets harder as the levels progress..........."
s$=s$+"I would like to say hello to the following people:"
s$=s$+" Nick Simpson - thanks for all your help and keep "
s$=s$+"up the good work; Marc Gale - coder of amazing "
s$=s$+"games and demos and currently running "
s$=s$+"www.ps2-yabasic.co.uk and to everyone else at "
s$=s$+"the message boards at www.yabasic.co.uk."
p=0
sxc=0
scy=450
repeat
setdrawbuf d
d=1-d
setdispbuf d
c=peek("port1")
mm=mm+.02
red=100*sin(mm)
grn=100*sin(mm/2)
blu=100*sin(mm/3)
setrgb 1,red,0,0
setrgb 2,0,grn,0
setrgb 3,0,0,blu
gtriangle 0,0 to 640,512 to 0,512
gtriangle 0,0 to 640,512 to 640,0
rem setrgb 1,red*2,grn*3,blu*2
setrgb 1,255,255,255    
    text 245-5+ran(5),180-2+ran(4),"L-A-B H-U-N-T-E-R"
    text 225-5,200-2+ran(4),"======================"
    text 195-5,240-2+ran(4),"Coded by Christopher Rankine"
    text 275-5,270-2+ran(4),"HI SCORE : "+str$(hi_score)
    text 255-5,290-2+ran(4),"PRESS X TO START"
    text 255-5,320-2+ran(4),"================"
text 205,340,"You have survived " + str$(com) + " time(s)"
text 205,360,"You have been killed " + str$(kill) + " time(s)"
if carkill>0 then
carper=(carkill/carescape)*100
else
carper=0
fi
text 205,380,str$(carescape) + " cars escaped"
text 205,400,"You have killed " + str$(carkill) + " cars"
text 205,420,"Percentage of cars killed : " + str$ (int(carper)) + " %"
text 205,440,"Max level reached : level " + str$(maxlev)
gosub scroller
until (and(c,16384)>0)
carkill=0
carescape=0
return






