ync on
sync rate 80
 
global posx#
global posy#
global movx#
global movy#
global ang#
global thrust#
global grav#
global angchange#
global shipsize#
global energyloss#
global nparticles
global particleadjust
global fuel#
global score = 0
global pow1x#
global pow1y#
global pow1a
global pow1s
 
pow1s =12
pow1a = rnd(359)
pow1y# = rnd(400)+40
pow1x# = rnd(400)+120
posx# = 320
posy# = 240
movx#=0
movy#=0
ang#=0
thrust#=0.07
grav#=0.4
angchange#=2
shipsize#=5
energyloss#=0.95
nparticles=200
particleadjust#=0.5
fuel#=50
 
dim particles#(nparticles,3) `x,y,life/size
`global emitp=0
for p=1 to nparticles
   particles#(p,3)=rnd(100)
   particles#(p,1)=-1000
   particles#(p,2)=-1000
next p
 
do
 
   `Draw_Spaceship()
   ink rgb(255,255,255),1
   circle posx#,posy#,5+shipsize
   line posx#,posy#,posx#+sin(ang#+20)*(10+shipsize),posy#+cos(ang#+20)*(10+shipsize)
   circle posx#+sin(ang#+20)*10,posy#+cos(ang#+20)*10,3+shipsize
 
   line posx#,posy#,posx#+sin(ang#-20)*(10+shipsize),posy#+cos(ang#-20)*(10+shipsize)
   circle posx#+sin(ang#-20)*10,posy#+cos(ang#-20)*10,3+shipsize
 
   `Movement_Routine()
   if upkey()=1
      movx#=movx#-sin(ang#)*thrust#
      movy#=movy#-cos(ang#)*thrust#
      if rnd(18)=1 then emitpar()
      fuel#=fuel#-0.02
   endif
   if downkey()=1
      movx#=movx#-sin(ang#+180)*(thrust#-0.01)
      movy#=movy#-cos(ang#+180)*(thrust#-0.01)
      if rnd(18)=1 then emitpar()
      fuel#=fuel#-0.01
   endif
   if leftkey()=1
      ang#=wrapvalue(ang#+angchange#)
   endif
   if rightkey()=1
      ang#=wrapvalue(ang#-angchange#)
   endif
 
   posx#=posx#+movx#
   posy#=posy#+movy#+grav#
 
   movx#=movx#*energyloss#
   movy#=movy#*energyloss#
 
   updateparticles()
 
   drawparticles()
 
 
   powerup( pow1x, pow1y, pow1a, pow1s,"F" )
   pow1a=wrapvalue(pow1a+1)
 
   drawhud()
 
   deathcheck()
 
   sync
   sleep 1
   cls
loop
 
function drawhud()
   ink rgb(255,int(fuel#)+105,int(fuel#)+105),1
   box 40,0,40+int(fuel#),15
   ink rgb(255,255,255),1
   print "FUEL:                         SCORE: " + str$(score)
   line 140,0,140,15
   line 140,0,140-(100-fuel),0
   line 40,0,40,15
   line 140,15,140-(101-fuel),15
 
endfunction
 
function powerup( x#, y#, angle, size, let$)
   ink rgb(255,255,255),1
   center text x#+1,y#-7,let$
   x1#=x#+sin(angle)*size
   y1#=y#+cos(angle)*size
   x2#=x#+sin(angle+90)*size
   y2#=y#+cos(angle+90)*size
   x3#=x#+sin(angle+180)*size
   y3#=y#+cos(angle+180)*size
   x4#=x#+sin(angle+270)*size
   y4#=y#+cos(angle+270)*size
   line x1#,y1#,x2#,y2#
   line x2#,y2#,x3#,y3#
   line x3#,y3#,x4#,y4#
   line x4#,y4#,x1#,y1#
endfunction
 
function checkpowerup()
 
 
 
 
endfunction
 
function emitpar()
   for p=1 to nparticles
      if particles#(p,3)=0 or particles#(p,3)>100
         particles#(p,1)=posx#
         particles#(p,2)=posy#
         particles#(p,3)=1
         exitfunction
      endif
   next p
endfunction
 
function updateparticles()
   for p=1 to nparticles
      if particles#(p,3)>100 or particles#(p,3)<1
         particles#(p,3)=0 `DEAD!
         else
         particles#(p,2)=particles#(p,2)+2
         particles#(p,3)=particles#(p,3)+1
      endif
   next p
endfunction
 
function drawparticles()
   for p=1 to nparticles
      if particles#(p,3)=0 or particles#(p,3)>100
         else
         `Draw...
         ink rgb(100-particles#(p,3),100-particles#(p,3),100-particles#(p,3)),1
         circle particles#(p,1),particles#(p,2),particles#(p,3)*0.15
      endif
   next p
endfunction
 
function deathcheck()
   if fuel#<=0
      do
         posx#=mousex()
         posy#=mousey()
         if (mousemovex()>0 or mousemovey()>0) and rnd(7)=3 then emitpar()
 
         updateparticles()
         drawparticles()
         ink 0,0
         box (screen width()/2)-200,(screen height()/2)-100,(screen width()/2)+200,(screen height()/2)+100
         ink rgb(255,255,255),1
         center text screen width()/2,screen height()/2,"GAME OVER!"
         line (screen width()/2)-200,(screen height()/2)-100,(screen width()/2)-200,(screen height()/2)+100
         line (screen width()/2)-200,(screen height()/2)-100,(screen width()/2)+200,(screen height()/2)-100
         line (screen width()/2)-200,(screen height()/2)+100,(screen width()/2)+200,(screen height()/2)+100
         line (screen width()/2)+200,(screen height()/2)-100,(screen width()/2)+200,(screen height()/2)+100
         `Play again etc... goes here.
         sync
         sleep 1
         cls
      loop
   endif
endfunction