open window 640,512

' CONTROLLER VALUES
U=16:D=64:L=128:R=32:X=16384:SQ=32768:TRI=4096:CIR=8192
R1=2048:R2=512:ST=8:L2=256:L1=1024

label main
gosub setup
wait .5
' AUTOPILOT IS ON
ap = 1 : ay = y : bb = 10

'===========
'   INTRO
'===========
txt = 600
repeat
 if int(ran(20)) = 2 then
   exx=50+ran(400)  :  eyy=100+ran(300)
   gosub init_new_expl
 endif

 txt = txt - 1
 TL = TL + .03
 if MT < 200 MT = MT + 1
 setrgb 1,0,MT,0 : text 120,250, fly$
 setrgb 1,100,100,100 : text 320,50, "FLYPHYSIC 1.0","cc"
 setrgb 1,130,100,130 : text txt,400, c$
 gosub new_screen : gosub draw_backround : gosub draw_explos
until(peek("port1")<>0)

'===========
'   GAME
'===========

goto game


label init_new_expl
 if dn+5 > dotnum dn=0
 for d = dn to dn+5
   exx(1,d) = exx      : exx(2,d) = eyy
   exx(3,d) = 2-ran(4) : exx(4,d) = 2-ran(4)
   exx(5,d) = 250
 next
  dn = d
return

label draw_explos
 for d = 1 to dotnum
  
  if exx(5,d) > 0 then

  exx(5,d) = exx(5,d) - 5
  exx(1,d) = exx(1,d) + exx(3,d)
  exx(2,d) = exx(2,d) + exx(4,d)

  setrgb 1,exx(5,d)+1.3,exx(5,d),0
  fill rect exx(1,d)-scr,exx(2,d)-scy,exx(1,d)+exx(5,d)/20-scr,exx(2,d)+exx(5,d)/20-scy
  endif
 next
return

label game_over
 setdrawbuf 1-buf
 setdispbuf 1-buf
 for dx = 0 to 640 step 32 : for dy = 2 to 514 step 32
  setrgb 1,dx/4,dy/2,dy/4
  fill rect dx+6,dy+6,dx+16,dy+16
 next : wait .03 : next

 setrgb 1,10,10,150:fill rect 190,200,440,316
 setrgb 1,210,210,150:text 320,258, "GAME OVER","cc" 
 wait 1
 repeat:until(peek("port1")<>0)
goto main

label new_screen
 setdispbuf buf
 buf = 1 - buf
 setdrawbuf buf
return


label draw_backround

 db = bb+scy/2-80

 setrgb 1,br,bg,bb+scy/4
 setrgb 2,br,bg,db
 setrgb 3,br,bg,bb+scy/4
 gtriangle 0,512 to 0,0 to 640,512
 setrgb 3,br,bg,db
 gtriangle 640,512 to 640,0 to 0,0

 if br>0 br = br - 1
 if bg>0 bg = bg - 1
 bb = 120
return



label draw_player
'RADAR
 rpx = 10+(scr/ls)*280

 setrgb 1,br,bg,db
 setrgb 2,10,110,10:setrgb 3,10,110,10
 gtriangle 280,10 to 2,10 to 2,70
 setrgb 3,br,bg,db
 gtriangle 280,70 to 2,70 to 280,10

 for c = 1 to po_num*3 step 3
'DRAW EFFECTS
if V > 0 then
  if fx(c/3,1) < fx(c/3,4) then
     fx(c/3,1) = px(1)+ran(5)
     fx(c/3,2) = py(1)+ran(15)
     fx(c/3,3) = 250
     fx(c/3,4) = px(1)-(V*10)-ran(20)
  endif
else
 if fx(c/3,1) > fx(c/3,4) then
     fx(c/3,1) = px(1)+ran(5)
     fx(c/3,2) = py(1)-ran(10)
     fx(c/3,3) = 250
     fx(c/3,4) = px(1)-(V*10)-ran(20)
 endif
endif

 fx(c/3,1) = fx(c/3,1) - (.1+V)
 fx(c/3,2) = fx(c/3,2) - (.1+W)
 fx(c/3,3) = fx(c/3,3) - 10

 setrgb 1,fx(c/3,3)+dmg,fx(c/3,3),(fx(c/3,2)/10)
 fill rect fx(c/3,1)-scr,fx(c/3,2)-scy,fx(c/3,1)-2-scr,fx(c/3,2)-2-scy
'END EFFECTS


'DRAW PLAYER

 setrgb 1,pc(c/3,1),pc(c/3,2),pc(c/3,3)
 setrgb 2,pc(c/3,1),pc(c/3,2),pc(c/3,3)
 setrgb 3,pc(c/3,1),pc(c/3,2),pc(c/3,3)

 gtriangle px(c)-scr,py(c)-scy to px(c+1)-scr,py(c+1)-scy to px(c+2)-scr,py(c+2)-scy

 if dmg<70 setrgb 1,dmg*2,250-dmg*2,0
 if dmg>70 setrgb 1,dmg*2-100*sin(TL),250-dmg*2,0

 fill triangle rpx+(x(c)/ps),25+(y(c)/ps) to rpx+(x(c+1)/ps),25+(y(c+1)/ps) to rpx+(x(c+2)/ps),25+(y(c+2)/ps)

 next

'DRAW BOOST
 fill rect 330,30,620-dmg*2.9,40
 setrgb 1,220-speed*50,speed*50,0
 fill rect 330,10,330+speed*58,20

'  - "TRAFFIC LIGHTS" -
 TL = TL + .05
 setrgb 1,250*sin(TL),255-250*sin(TL),0
 fill rect px(16)-scr,py(16)-scy,px(16)-scr+(3/ps),py(16)+(3/ps)-scy

 setrgb 1,255-250*sin(TL),250*sin(TL),0
 fill rect px(14)-scr,py(14)-scy,px(14)-scr+(3/ps),py(14)+(3/ps)-scy

 fill rect px(8)-scr,py(8)-scy-(1.5/ps),px(8)-scr+(3/ps),py(8)-scy+(1.5/ps)
return



label draw_level
 setrgb 1,0,50,0
 fill rect 0,480-scy,640,512-scy

 for l = 1 to lesize

 if le(l,3)=3 and e(l,8)<99 then
'ENEMY ON RADAR
  rx = (e(l,1)-scr)/4
  if rx>5 and rx<280 then
  setrgb 1,0+rx,200-rx,200-rx
  fill rect rx,68,rx-7,60
  endif
 endif

 le(l,1) = l*lxs

 on le(l,3)+1 goto 0,need1,need2,eneneed

 label eneneed
  if(e(l,1)-scr>-100)and(e(l,1)-scr<640) goto enemy
 goto 0

 label need1
  if(le(l,1)-scr>-100)and(le(l,1)-scr<700) goto 1
 goto 0

 label need2
  if(le(l,1)-scr>-100)and(le(l,1)-scr<700) goto 2
 goto 0
1
 setrgb 1,100+le(l,4),100+le(l,4),100+le(l,4)
 fill rect le(l,1)-scr,430-scy,le(l,1)-scr+40,480-scy
 fill triangle le(l,1)-scr,430-scy to le(l,1)-scr,480-scy to le(l,1)-scr-20,480-scy
 fill triangle le(l,1)-scr+40,430-scy to le(l,1)-scr,480-scy to le(l,1)-scr+60,480-scy
 setrgb 1,10+le(l,4),10+le(l,4),10+le(l,4)
 fill rect le(l,1)-scr,465-scy,le(l,1)-scr+22,480-scy

goto 0

2
 setrgb 1,60,30,0
 fill rect le(l,1)-scr-5,480-scy,le(l,1)-scr+5,470-scy

 setrgb 1,10,130+le(l,4),10
 fill triangle le(l,1)-10-scr,470-scy to le(l,1)-scr,430-le(l,4)-scy to le(l,1)+10-scr,470-scy

goto 0

0

 next
return



label enemy

 if e(l,8) < 100 then

 e(l,7) = e(l,7) + 1
 ae = e(l,1)-x

 if abs(ae) < 350 then

 if e(l,7) > 30 then
  esh = esh + 1 : if esh > 4 esh = 0
  e(esh,3) = e(l,1)+20 : e(esh,4) = e(l,2)-30
  e(esh,5) = -ae/20
  e(esh,6) = -10 : e(l,7) = 0
 endif
 
 else

 e(l,7) = 0

 endif

 xx = e(l,1)-scr : yy = e(l,2)-scy
 ae=ae / 20

 if e(l,7) = 0 then
  as = 20
 else
  if as>0 as = as - 3
 endif
 
 setrgb 1,100+e(l,8)/2,80,10
 fill rect xx,yy,xx+40,yy-30
 setrgb 1,140,150,110
 fill triangle xx+10,yy-30 to xx+15,yy-30 to xx+10-ae,yy-80+as
 fill triangle xx+20,yy-30 to xx+25,yy-30 to xx+20-ae,yy-80+as

'COLLISION DETECT
 for g = 1 to 5
 if g(g,6) = 1 then
  if( g(g,1)-scr>xx ) and ( g(g,1)-scr<xx+40 ) then
  if( g(g,2)-scy<yy ) and ( g(g,2)-scy>yy-30 ) then
   
   for c=1 to 6: g(g,c) = 0 :next
   e(l,8) = e(l,8) + 20

   if e(l,8) >= 100 then
   exx = xx+5+scr:eyy=yy-10+scy
   gosub init_new_expl
   endif
 endif:endif:endif
 
 if g(g,6) = 2 then
  if( g(g,1)-scr>xx-60 ) and ( g(g,1)-scr<xx+100 ) then
  if( g(g,2)-scy<yy+60 ) and ( g(g,2)-scy>yy-30 ) then
 
   for c=1 to 6: g(g,c) = 0 :next
   e(l,8) = e(l,8) + 100
   br=br+30:bg=bg+20
   exx=xx+5+scr : eyy=yy-10+scy
   gosub init_new_expl

 endif:endif:endif
 next
 endif
goto 0
return


label play
 k = peek("port1")

 if and(k,R1)<>0 sdelay = sdelay + 1
 bdelay = bdelay + 1

 if (and(k,R1)<>0)and(p2=0) then rem ........GUN
  sh = sh + 1 : if sh > 4 sh = 0
  g(sh,6) = 1 : g(sh,3) = (x-px(1))/4
  g(sh,4) = W*4 : g(sh,2) = py(3)
  g(sh,1) = px(7) : p2 = 1
 endif

 if(and(k,CIR)<>0)and(bdelay>70) then rem ...BOMB
  sh = sh + 1 : if sh > 9 sh = 0
  g(sh,6) = 2 : g(sh,4) = (x-px(1))/20
  g(sh,3) = 1.5 : g(sh,2) = py(3)
  g(sh,1) = px(7) : bdelay = 0
 endif

 gosub shot

 if (and(k,1)<>0)and(p1=0) then
  if(ap=1)and(p1=0) then:ap=0:p1=1:fi
  if(ap=0)and(p1=0) then:ap=1:p1=1:aa=a:fi
 endif

 if and(k,1) <> 1 p1 = 0
 if(and(k,R1)<>R1)or(sdelay>5) then:p2=0:sdelay=0:fi

 gosub fly
 a=a+and(k,U)/(U*(speed/5))-and(k,D)/(D*(speed/5))
 a=mod(a+360,360)

 for b = 1 to po_num*3
  px(b)=x+(x(b)*co(a)-y(b)*si(a))
  py(b)=y+(x(b)*si(a)+y(b)*co(a))
 next
return


label shot
 for g = 1 to 5

 on g(g,6) goto 11,12 rem GUN or BOMB

11 rem ***GUN***
 g(g,1) = g(g,1) + g(g,3)
 g(g,2) = g(g,2) + g(g,4)

 setrgb 1,240,250,10
 line g(g,1)-scr,g(g,2)-scy,g(g,1)-scr+g(g,3)*2,g(g,2)-scy+g(g,4)*2
 goto 00

12 rem ***BOMB***
 g(g,1) = g(g,1) + g(g,3)
 g(g,2) = g(g,2) + g(g,4)
 g(g,4) = g(g,4) + .11

 setrgb 1,0,0,0
 fill rect g(g,1)-scr,g(g,2)-scy,g(g,1)-scr+7,g(g,2)-scy+7
 goto 00

00 rem ***ENEMY SHOT***
 e(g,3) = e(g,3) + e(g,5)
 e(g,4) = e(g,4) + e(g,6)

 setrgb 1,240,250,10
 line e(g,3)-scr,e(g,4)-scy,e(g,3)-scr+e(g,5)*2,e(g,4)-scy+e(g,6)*2

'COLLISION DETECT
'-----=CHECK X AREA=-----
  if( e(g,4) < py(5) ) or ( e(g,4) < y     ) then
  if( e(g,4) > py(1) ) or ( e(g,4) > py(3) ) then
'-----=CHECK Y AREA=-----
  if( e(g,3) > px(5) ) or ( e(g,3) > x     ) then
  if( e(g,3) < px(1) ) or ( e(g,3) < px(3) ) then

   dmg = dmg + 5
   br = 100
   exx= e(g,3) : eyy=e(g,4)
   gosub init_new_expl
   e(g,3)=0:e(g,4)=0
 
 endif:endif:endif:endif

 next
return


label fly
 if ap=1 gosub autopilot
 if speed < 5 speed = speed + and(k,X)/(X*20)
 if speed >.5 speed = speed - and(k,SQ)/(SQ*10)
 if speed >.5 speed = speed - .015


 V = ((x-px(1))/30)*speed/2
 W = ((2.5-speed/2)+(si(a)*speed))
 x = x + V

 if(py(3)<480)and(py(1)<480) then
  y = y + W
 else
  y = 405 : a = a - (W*V)*7 : dmg=dmg+80
 endif

 if(a>270)or(a <90) a = a + (5-speed)/7
 if(a>90)and(a<270) a = a - (5-speed)/7


'X/Y SCROLL
 if x-scr > 400 scr = scr + V
 if x-scr < 100 scr =scr + V
 if y-scy<108 scy = scy + W
 if y-scy>158 scy = scy + W
 if y > 158 scy = 0
 
 if scr>ls+100 then
  scr=-300:x=300+scr:bg=250:br=100:fi
 if scr<-350 then
  scr=ls+99
  x=100+scr:bg=250:br=200:fi
return



label autopilot
 mat = mat + .2
 if speed < 5 and dmg<80 speed=speed+.04

 if aa > 90 and aa < 270 then
 if(int(a)>1)and(a>180) a=a-.8
 if(int(a)>1)and(a<180) a=a+.7
 else
 if(int(a)>1)and(a>180) a=a+.7
 if(int(a)>1)and(a<180) a=a-.8
 endif
 
 a=mod(a+360,360)

 acol = 140-sin(mat)*50
 setrgb 1,acol,acol,acol
 text 23,100, "AUTOPILOT","lc"
 fill rect 12,92,22,101
return


label game
 gosub new_screen
 gosub draw_backround
 gosub play
 gosub draw_player
 gosub draw_level
 gosub draw_explos
 if dmg > 100 or k=ST goto game_over
goto game


label setup
 fly$ = "X - BOOST\nSQUARE - BRAKE\nSELECT - AUTOPILOT ON/OFF\nCIRCLE - DROP BOMB\nR1 - GUN"
 c$ = "Developed by Stefan Tapper"
 c$ = c$+"         Thanks to yabasic.co.uk and ps2-yabasic.co.uk for"
 c$ = c$+" the helpful tutorials and all the nice guys at the forums."
'PLANE SIZE
 ps = 1.5
'DAMAGE
 dmg=0
'NUMBER OF TRIANGLES IN PLAYER PLANE
 po_num = 6

'COORDINATES IN PLAYER PLANE
 v = po_num*3

 V = 0 rem CALCULATED >X< SPEED
 W = 0 rem CALCULATED >Y< SPEED

 dim x(v),y(v),px(v),py(v),si(360),co(360),pc(v,3)
 dim fx(20,4), g(10,6)

 speed = 5
 scr = -300 : scy = 0 : a = 0 : x = 100+scr : y = 258

'BACKROUND
 br=0:bg=0:bb=100 rem COLOURS

 for b = 0 to 360
  si(b)=sin(b/180*pi)
  co(b)=cos(b/180*pi)
 next

 dotnum = 30
 dim exx(5,dotnum)

 gosub plane  :  gosub level
return


label plane
 restore plane

 for c = 1 to po_num*3
  read x(c),y(c)
  x(c) = x(c)/ps   :   y(c) = y(c)/ps
 next

 restore plane_colour

 for c = 0 to po_num
'COLOUR RED    GREEN   BLUE
  read pc(c,1),pc(c,2),pc(c,3)
 next


rem            -PLANE-
rem  -X- -Y- -X- -Y- -X- -Y- | -X- -Y- -X- -Y- -X- -Y-
data -80, 0 , 0 , 0 , 0 , 20,  -80, 0 ,-80, 20, 0 , 20
data  0 , 0 , 30, 20, 0 , 20,   0 , 0 , 0 , 12, 17, 12
data  30, 19,-90, 40,-80, 19,  -85,-30,-80, 1 ,-55, 1 
return

label plane_colour
data 140,140,180, 140,140,180,  90, 90, 90
data 100,120,230,  90, 90, 90,  70, 70,170
data  0 , 0 , 0
return


label level
 lesize=80  :  lxs=150  :  ls = lesize*lxs
 restore level

 dim le(lesize,4), e(lesize,8)

 for l = 1 to lesize
  read le(l,3)
  le(l,4) = ran(40)

  if le(l,3) = 3 then
   e(l,2) = 480    :    e(l,1) = l*lxs
  endif

  for l1 = 3 to 8:e(l,l1)=0:next
 next
data 0,2,3,0,3,0,1,3,0,1
data 0,2,3,2,2,2,0,3,2,1
data 2,2,2,2,3,2,1,2,2,1
data 2,3,2,3,2,1,3,1,2,0
data 0,2,3,0,3,0,1,3,0,1
data 0,2,3,2,2,2,0,3,2,1
data 2,2,2,2,3,2,1,2,2,1
data 2,3,2,3,2,1,3,1,2,0
return




  
