''''' PROTECTOR
''''' BY JO
''''' 2002


''''''''SET UP ALL STUFF
power=590
bull=475
c=0
s=10
r=30
angle=0
dim cosines(360)
dim sines(360)
for angle=0 to 360
cosines(angle)=cos(angle*(pi/180))
sines(angle)=sin(angle*(pi/180))
next angle
dim ex(2)
dim ey(2)
dim ex2(2)
dim ey2(2)
dim sx(10)
dim sy(10)
dim sx2(15)
dim sy2(15)
for a=1 to 10
sx(a)=ran(640)
sy(a)=ran(512)+ran(270)
sx2(a)=ran(640)
sy2(a)=ran(512)+ran(270)
next a

open window 640,512
window origin "lb"
angle=0

''''''''''''''GOTO THE MENU
gosub setscroll
gosub menu


''''''''START MAIN LOOP

label loop
setdrawbuf dw
dw=1-dw
setdispbuf dw
clear window
gosub keys
gosub collision
gosub space
gosub enemy
gosub ship
gosub energy
shoot=0
boom=0
'''''' GOTO START OF LOOP
goto loop


'''''''''''''DRAW THE MENU
label menu
repeat
setdrawbuf dw
dw=1-dw
setdispbuf dw
clear window
setrgb 1,200,200,200
text scx,450,mid$(s$,p,67)
scx=scx-2
if scx<-10 then
scx=scx+10
p=p+1
if p>len(s$) p=0
endif
setrgb 1,100,100,200
line 0,400 to 640,400
line 0,100 to 640,100
aa=aa+.1
col=100+100*sin(aa)
setrgb 1,50+col,50+col,50+col*2
fill rect 220,150 to 270,350
fill rect 270,350 to 360,220
text 290,175,"R O T E C T O R"
setrgb 1,200,200,200
text 210,50,"PRESS X TO BEGIN BATTLE"
text 160,30,"WARNING: CONTAINS FLASHING LIGHTS"
setrgb 1,0,0,0
fill rect 270,250 to 320,320
if peek("port1")=16384 start=1
until (start=1)
beep
wait 2
goto loop


label space

''''''''''''' DRAW TOP STARS

if poo=1 cc=cc+5
if poo=0 cc=cc-5
if cc>100 poo=0
if cc<50 poo=1
setrgb 1,cc-25,cc-25,cc
for a=1 to 10
fill rect sx(a),sy(a) to sx(a)+4,sy(a)+4
sy(a)=sy(a)-5
if sy(a)<0 sx(a)=ran(640)
if sy(a)<0 sy(a)=512
next a

''''''''''''' DRAW BACK STARS

for a=1 to 10
fill rect sx2(a),sy2(a) to sx2(a)+2,sy2(a)+2
sy2(a)=sy2(a)-3
if sy2(a)<0 sx2(a)=ran(640)
if sy2(a)<0 sy2(a)=512
next a
return



label energy

''''''''''''' DRAW ENERGY
setrgb 1,100,100,200
setrgb 2,100,100,200
setrgb 3,0,0,10
gtriangle 0,0 to 0,512 to 50,512
setrgb 2,0,0,10
gtriangle 0,0 to 50,0 to 50,512 
setrgb 1,100,100,100
setrgb 2,50,0,50
setrgb 3,50,0,50
gtriangle 0,30 to 0,0 to 640,0
setrgb 1,100,100,100
setrgb 2,100,100,100
setrgb 3,50,0,50
gtriangle 0,30 to 640,30 to 640,0
setrgb 1,200,200,0
setrgb 1,100,100,200
fill rect 150,11 to power,17
setrgb 1,0,0,0
rect 150,11 to 590,17
text 20,10,"E N E R G Y:"

''''''''''''' DRAW AMMO BAR
setrgb 1,300-bull,bull-200,0
fill rect 20,40 to 30,bull-10
setrgb 1,0,0,0
rect 20,40 to 30,460
''''''''''''DRAW AMMO WARNING IF BULLETS LOW
if bull<200 then
aa=aa+.1
col=100*sin(aa)
setrgb 1,col,col*2,col
text 220,256,"WARNING! LASER LOW!"
endif

'''''''''DRAW TEXT BAR AT TOP
setrgb 1,100,100,200
setrgb 2,100,100,200
setrgb 3,50,50,100
gtriangle 0,512 to 640,512 to 0,480
setrgb 1,50,50,100
gtriangle 0,480 to 640,512 to 640,480
setrgb 1,0,0,0
fill rect 100,485 to 540,510
setrgb 1,200,200,200
aa=aa+.1
col=50*sin(aa)
setrgb 1,100+col,100+col,100+col*2
text 230,493,"P R O T E C T O R"
return 

label ship

'''''''''''''''' DRAW PLAYERS SHIP
setrgb 1,250,0,0
setrgb 2,100,100,100
setrgb 3,20,0,0

gtriangle fx+261,fy+80 to fx+246,fy+60 to fx+276,fy+60
gtriangle fx+240,fy+50 to fx+246,fy+50 to fx+246,fy+60
gtriangle fx+280,fy+50 to fx+276,fy+50 to fx+276,fy+60
col=ran(250)
setrgb 1,col,col,0
fill circle fx+261,fy+50,7

'''''''''IF PLAYER IS BEING HIT THE DRAW BANG
'''''''''USES MARC GALE'S FAST BALL ROUTINE
if phi=1 then
setrgb 1,ran(200),0,0
setrgb 2,0,0,0
setrgb 3,0,0,0
ang=0
repeat
xo1=cosines(ang)*r:yo1=sines(ang)*r
xo2=cosines(ang+s)*r:yo2=sines(ang+s)*r
gtriangle fx+261,fy+60 to fx+261+xo1,fy+60+yo1 to fx+261+xo2,fy+60+yo2
gtriangle fx+261,fy+60 to fx+261-xo1,fy+60+yo1 to fx+261-xo2,fy+60+yo2
gtriangle fx+261,fy+60 to fx+261-xo1,fy+60-yo1 to fx+261-xo2,fy+60-yo2
gtriangle fx+261,fy+60 to fx+261+xo1,fy+60-yo1 to fx+261+xo2,fy+60-yo2
ang=ang+s
until (ang>90)
endif
phi=0

'''''''''''''''DRAW LASER IF X IS PRESSED
if shoot=1 then
setrgb 1,ran(250),ran(250),ran(250)
for a=0 to 432 step ran(10)
fill rect fx+260,80+a to fx+262,80+a+2
next a

endif
return

label keys
''''''''''''''CHECK TO SEE IF PLAYER IS PRESSING ANYTHING
c=peek("port1")
if (and(c,128)<>0) fx=fx-10
if (and(c,32)<>0) fx=fx+10
if (and(c,16384)<>0) shoot=1
if (and(c,16384)<>0) bull=bull-1
if shoot=0 bull=bull+.3
if bull>470 bull=470
if bull<50 shoot=0
if bull<50 bull=50

return


'''''''''''''''DRAW THE ENEMYS
label enemy
for a=1 to 2
setrgb 1,100,100,200
setrgb 2,100,200,100
setrgb 3,200,100,200
gtriangle ex(a)+10,ey(a)-20 to ex(a),ey(a) to ex(a)+20,ey(a)
gtriangle ex(a)+10,ey(a)+10 to ex(a),ey(a) to ex(a)+20,ey(a)
line ex(a),ey(a) to ex(a),ey(a)+20
line ex(a)+20,ey(a) to ex(a)+20,ey(a)+20
setrgb 1,ran(250),ran(250),0
fill circle ex(a)+10,ey(a)+15,5
setrgb 1,100,100,200
setrgb 2,100,200,100
setrgb 3,200,100,200
ey(a)=ey(a)-3
if ey(a)<0 ex(a)=ran(500)+50
if ey(a)<0 ey(a)=512+ran(500)
setrgb 1,100,100,100
fill rect ex2(a)+5,ey2(a) to ex2(a)+15,ey2(a)+20
fill circle ex2(a)+10,ey2(a),5
setrgb 1,200,0,0
setrgb 2,200,0,0
setrgb 3,0,0,0
gtriangle ex2(a)+5,ey2(a)+20 to ex2(a)+15,ey2(a)+20 to ex2(a)+10,ey2(a)+30
ey2(a)=ey2(a)-7
if ey2(a)<0 ex2(a)=ran(500)+50
if ey2(a)<0 ey2(a)=512+ran(500)
ex(a)=ex(a)+sines(angle)*10
ey(a)=ey(a)+cosines(angle)/10
ex2(a)=ex2(a)+sines(angle)*10
ey2(a)=ey2(a)+cosines(angle)/10
next a
angle=angle+10
angle=mod(angle+360,360)
return

''''''''''''''''CHECK TO SEE IF YOU'VE SHOT SOMETHING
label collision
for a=1 to 2
if shoot=1 and fx+261<ex(a)+20 and fx+261>ex(a) and ey(a)>fy+80 then
ex(a)=ran(500)+50
ey(a)=512+ran(500)
setrgb 1,255,0,0
fill rect 0,0 to 640,512
kills=kills+1
endif
next a

for a=1 to 2
if shoot=1 and fx+261<ex2(a)+20 and fx+261>ex2(a) and  ey2(a)>fy+80 then
ex2(a)=ran(500)+50
ey2(a)=512+ran(500)
setrgb 1,255,0,0
fill rect 0,0 to 640,512
bull=bull+10
kills=kills+1
endif
next a
''''''' CHECK TO SEE IF ENEMY HAS GONE PAST OR HIT YOU
for x=1 to 2
if ex(x)<fx+276 and ex(x)>fx+246 and ey(x)<fy+80 then
power=power-5
phi=1
endif
if ex2(x)<fx+276 and ex2(x)>fx+246 and ey2(x)<fy+80 then
power=power-10
phi=1
endif
if ey(x)<10 power=power-7
if ey2(x)<10 power=power-10
next x
if power<250 then
aa=aa+.1
col=100*sin(aa)
setrgb 1,col,col,0
text 215,236,"WARNING! HEALTH LOW!"
endif
''''''''' SEE IF YOU ARE DEAD
if power<150 gosub death

''''''''' SEE IF PLAYER HAS KILLED ENOUGH ENEMYS
if kills>250 gosub win
return


label death
beep
setrgb 1,255,0,0
fill rect 0,0 to 640,512
wait 2
close window
open window 640,512
window origin "lb"
setrgb 1,100,100,200
text 225,250,"Y O U  D I E D!"
text 160,180,"PRESS START AND SELECT TO EXIT"
text 200,160,"PRESS X TO TRY AGAIN"
text 190,20,"PROTECTOR BY JO MORROW"
power=590
bull=512
for a=1 to 2
ex(a)=ran(500)+50
ey(a)=512+ran(500)
kills=0
ex2(a)=ran(500)+50
ey2(a)=512+ran(500)
next a
repeat
if peek("port1")=16384 gosub menu
until (1=2)

label setscroll
s$="                                                                   "
s$=s$+".:  Welcome to Protector. Created bu Jo Morrow."
s$=s$+" Use left and right to move the ship and press X"
s$=s$+" to fire your laser. The laser will run out of"
s$=s$+" energy the more you use it. The laser will"
s$=s$+" recharge automatically every time you stop"
s$=s$+" firing it. The amount of charge the laser has"
s$=s$+" Is shown on the left hand side of the screen by a"
s$=s$+" green bar. The aim is to kill enough enemy"
s$=s$+" Destroyers and missiles to save your planet."
s$=s$+" Energy will be lost every time you are hit by an"
s$=s$+" enemy and every time an enemy gets past you."
s$=s$+" This energy can not be regained."
s$=s$+" SHOUT OUTS: Hi Shockwave, Demoneye"
s$=s$+", Xalthorn, Doctor, Dougal, Snakedogg, Zingy,"
s$=s$+" Jinx, KayatAvl and the rest of the yabasic crew."
s$=s$+" Visit www.yabasic.co.uk, www.ps2-yabasic.co.uk"
s$=s$+" and www.yabasic.150m.com  :."
p=0
scx=0
return


label win
close window
open window 640,512
window origin "lb"
setrgb 1,200,200,200
text 180,256,"Well done Protector! You win!"
text 175,236,"PRESS START AND SELECT TO EXIT"
text 155,206,"SORRY FOR THE RUBBISH ENDING SCREEN"
text 165,186,"BIT OF AN ANTI CLIMAX WASN'T IT?"
repeat
until (1=2)



