rem LOADING IMAGES
rem ==============
load image 0,"data/plane1.bmp"
load image 1,"data/plane2.bmp"
load image 2,"data/plane3.bmp"
load image 3,"data/bullet.bmp"
load image 4,"data/sea.bmp"
load image 5,"data/enemy1.bmp"
load image 6,"data/enemy2.bmp"
load image 7,"data/enemy3.bmp"
for i=0 to 5
load image i+8, "data/explosion"+str(i+1)+".bmp"
next
for i=0 to 6
load image i+14, "data/bigexplosion"+str(i+1)+".bmp"
next
for i=0 to 2
load image i+21 ,"data/island"+str(i+1)+".bmp"
next
for i=0 to 2
load image i+24 ,"data/superenemy"+str(i+1)+".bmp"
next
load image 27, "data/enemybullet.bmp"
load image 28,"data/menu.bmp"
load image 29,"data/arrow.bmp"
load image 30,"data/big logo.bmp"
load image 31,"data/life.bmp"
load image 32,"data/logo.bmp"

load sound 1,"data/shoot.wav"
load sound 2,"data/explosion.wav"
load sound 3,"data/collide.wav"
load sound 4,"data/plane_shot.wav"

set redraw off

rem TELLING HOW MUCH DECIMALS WE WANT
rem =================================
set decimal 1

rem MAKING THEM TRANSPARENT
rem =======================
for i=0 to 31
if i<>4 or (i<30 and i>27) then set image colorkey i,true
rem 0,67,171
next

rem TILING THE BACKGROUND
rem =====================
backgroundX[(640/32)+1]
backgroundY[(480/32)+1]
transitionX[(640/32)+1]
transitionY[(480/32)+1]
for i=0 to 640/32
backgroundX[i]=i*32
transitionX[i]=i*32
for a=0 to 480/32
backgroundY[a]=a*32
transitionY[a]=a*32
next
next

rem OUR SIMPLE COLLISION DETECTION FUNCTION
rem ===========================================
function RectangleCol(x1, y1, w1, h1, x2, y2, w2, h2)
if x1 > x2 + w2 or x1 + w1 < x2 then return false
if y1 > y2 + h2 or y1 + h1 < y2 then return false
return true
endfunc

rem THIS IS WHERE THE FUN BEGINS
rem ============================
do

rem A GAME MENU TO START WITH
rem =========================
menu=0
do
set color 0,0,0,255
cls
set color 255,255,255
draw image 30 ,(640/2)-(width(30)/2),5
draw image 28, (640/2)-(width(28)/2),height(30)+30
draw image 29, ((640/2)-(width(28)/2))-width(29),height(30)+(30+menu*19)
if keydown(38,true) then menu=menu-1
if keydown(40,true) then menu=menu+1
if menu>1 then menu=0
if menu<0 then menu=1
if keydown(" ") and menu=0 then break
if keydown(" ") and menu=1 then
quit=1
break
endif
redraw
wait 23
loop
for i=0 to 640/32
for z=0 to 480/32
draw image 4,transitionX[i],transitionY[z]
wait 1/2
redraw
next
next

rem INITIALIZING VARIABLES AND ARRAYS
rem =================================
frame=0
explo_frame=0
bigexplo_frame=0
bigexplox=-70
bigexploy=-70
explo2_frame=0
speed=4
scrollspeed = 1
planex=320
planey=480-128
enemyX[5]
enemyY[5]
superenemyX[5]
superenemyY[5]
decision[2]
enemybulletX[2]
enemybulletY[2]
enemyshot[2]
enemyshot[0]=0
enemyshot[1]=0
bulletx=-30
bullety=-30
shot=0
explox=-30
exploy=-30
explo2x=-30
explo2y=-30
score=0
lives=3
health=100
bullseye=1
shots_fired=1
bigexploactive=0
islandImage[3]
islandX[3]
islandY[3]

rem SETTING THE POSITIONS OF THE ENEMY PLANES
rem =========================================
for i=0 to 4
do
enemyX[i]=rnd(608)
until enemyX[i]>32
enemyY[i]=-rnd(100)-32
next
for i=0 to 1
do
superenemyX[i]=rnd(608)
until superenemyX[i]>32
superenemyY[i]=-rnd(100)-32
enemybulletX[i]=superenemyX[i]+17
enemybulletY[i]=superenemyY[i]+17
next

rem SETTING THE POSITIONS AND STARTING IMAGES OF THE ISLANDS
rem ========================================================
for i=0 to 2
do
islandX[i]=rnd(608)
until islandX[i]>32
islandY[i]=-rnd(100)
next
for i=0 to 2
islandImage[i]=i+21
next

rem THE 'ACTUAL' GAME LOOP
rem ======================
do
if quit=1 then break

rem CLEARING THE SCREEN
rem ===================
set color 0,0,0
cls
set color 255,255,255

rem MOVING THE PLAYER WITH THE ARROW KEYS
rem =====================================
rem OH, AND SHOOTING WITH THE SPACEBAR
rem ==================================
if keydown(27) then
wait 2000
cls
end
endif
if keydown(38) then planey=planey-speed
if keydown(40) then planey=planey+4
if keydown(37) then planex=planex-speed
if keydown(39) then planex=planex+speed
if keydown(" ",true) and shot=0
play sound 1
bulletx=planex+17
bullety=planey+5
shot=1
shots_fired=shots_fired+1
endif

rem MOVING THE ENEMY PLANES
rem =======================
for z=0 to 4
if enemyY[z]>480 then
do
enemyX[z]=rnd(608)
until enemyX[z]>32
enemyY[z]=-rnd(100)-32
else
enemyY[z]=enemyY[z]+speed
endif
next
for z=0 to 1
if superenemyY[z]>480 then
do
superenemyX[z]=rnd(608)
until superenemyX[z]>32
superenemyY[z]=-rnd(100)-32
else
superenemyY[z]=superenemyY[z]+speed
endif
next

rem MOVING THE ISLANDS
rem ==================
for z=0 to 2
if islandY[z]>480 then
do
islandX[z]=rnd(536)
until islandX[z]>32
do
islandY[z]=-rnd(100)
until islandY[z]>-64
islandImage[z]=rnd(3)+21
else
islandY[z]=islandY[z]+3
endif
next

rem CHECKING WHEN WE BEAT OR BEING BEATEN
rem =========================
for t=0 to 4
if RectangleCol(planex,planey,width(0),height(0),enemyX[t],enemyY[t],width(5),height(5)) then
if explox>0 then
explo2x=enemyX[t]
explo2y=enemyY[t]
else
explox=enemyX[t]
exploy=enemyY[t]
endif
play sound 3
do
enemyX[t]=rnd(608)
until enemyX[t]>32
enemyY[t]=-rnd(100)-32
health=health-25
if health<=0 then
bigexploactive=1
bigexplox=planex
bigexploy=planey
planex=-70
planey=-70
endif
do
enemyX[t]=rnd(608)
until enemyX[t]>32
enemyY[t]=-rnd(100)-32
endif
if shot=1 then
if RectangleCol(bulletx,bullety,width(3),height(3),enemyX[t],enemyY[t],width(5),height(5)) then
if explox>0 then
explo2x=enemyX[t]
explo2y=enemyY[t]
else
explox=enemyX[t]
exploy=enemyY[t]
endif
play sound 2
do
enemyX[t]=rnd(608)
until enemyX[t]>32
enemyY[t]=-rnd(100)-32
bulletx=-30
bullety=-30
score=score+50
bullseye=bullseye+1
endif
endif
next
for t=0 to 1
if RectangleCol(planex,planey,width(0),height(0),superenemyX[t],superenemyY[t],width(5),height(5)) then
if explox>0 then
explo2x=enemyX[t]
explo2y=enemyY[t]
else
explox=enemyX[t]
exploy=enemyY[t]
endif
play sound 3
do
enemyX[t]=rnd(608)
until enemyX[t]>32
enemyY[t]=-rnd(100)-32
health=health-25
if health<=0 then
bigexploactive=1
bigexplox=planex
bigexploy=planey
planex=-70
planey=-70
endif
do
enemyX[t]=rnd(608)
until enemyX[t]>32
enemyY[t]=-rnd(100)-32
endif
if RectangleCol(bulletx,bullety,width(3),height(3),superenemyX[t],superenemyY[t],width(5),height(5)) then
if explox>0 then
explo2x=superenemyX[t]
explo2y=superenemyY[t]
else
explox=superenemyX[t]
exploy=superenemyY[t]
endif
play sound 2
do
superenemyX[t]=rnd(608)
until superenemyX[t]>32
superenemyY[t]=-rnd(100)-32
bulletx=-30
bullety=-30
score=score+100
bullseye=bullseye+1
endif
next
for t=0 to 1
if enemyshot[t]=1 then
if RectangleCol(planex,planey,width(0),height(0),enemybulletX[t],enemybulletY[t],width(27),height(27)) then
health=health-10
if health<=0 then
bigexploactive=1
bigexplox=planex
bigexploy=planey
bulletx=-30
bullety=-30
endif
play sound 4
if explox>0 and explox<640 then
explox2=enemybulletX[t]
exploy2=enemybulletY[t]
else
explox=enemybulletX[t]
exploy=enemybulletY[t]
endif
enemybulletX[t]=superenemyX[t]+1
enemybulletY[t]=superenemyY[t]+7
enemyshot[t]=0
endif
endif
next

rem FLYING OVER THE ENDLESSLY SCROLLING SEA
rem =======================================
for w=0 to 15
backgroundY[w]=backgroundY[w]+3
if backgroundY[w]>480 then
backgroundY[w]=backgroundY[w]-512
endif
for q=0 to 19
draw image 4,backgroundX[q],backgroundY[w]
next
next

rem WHICH LOOKS DULL WITHOUT ISLANDS
rem ================================
for o=0 to 2
draw image islandImage[o],islandX[o],islandY[o]
next

rem KEEPING OUR PLANE IN THE SCREEN AND DISPLAY IT
rem ==============================================
frame=frame+1
if frame>2 then frame=0
if planex<0 and bigexploactive=0 then planex=0
if planey<0 and bigexploactive=0 then planey=0
if planex+width(0)>640 then planex=640-width(0)
if planey+height(0)>480-64 then planey=480-height(0)-64
draw image frame,planex,planey

rem WE HAVE TO SEE WHAT WE ARE FIGHTING
rem ===================================
for x=0 to 4
draw image frame+5,enemyX[x],enemyY[x]
next
for i=0 to 1
if enemyshot[i]=0 then
decision[i]=rnd(50)
endif
if decision[i]=9 then
if enemybulletY[i]<480
enemybulletY[i]=enemybulletY[i]+10
enemyshot[i]=1
else
enemybulletX[i]=superenemyX[i]+1
enemybulletY[i]=superenemyY[i]+7
enemyshot[i]=0
endif
else
enemybulletX[i]=superenemyX[i]+1
enemybulletY[i]=superenemyY[i]+7
enemyshot[i]=0
endif
draw image 27,enemybulletX[i],enemybulletY[i]
next
for x=0 to 1
draw image frame+24,superenemyX[x],superenemyY[x]
next

rem AND WITH WHAT
rem =============
if bullety>0 then
bullety=bullety-speed*2
else
bulletx=-30
bullety=-30
shot=0
endif
draw image 3,bulletx,bullety

rem A NICE EXPLOSION
rem ================
if explo_frame<5 and explox>0 then
explo_frame=explo_frame+1
else
explo_frame=0
explox=-30
exploy=-30
endif
draw image explo_frame+8,explox,exploy

rem A SECOND NICE EXPLOSION
rem =======================
if explo2_frame<5 and explo2x>0 then
explo2_frame=explo2_frame+1
else
explo2_frame=0
explo2x=-30
explo2y=-30
endif
draw image explo2_frame+8,explo2x,explo2y

rem A BIGGER EXPLOSION
rem ==================
if bigexploactive=1 then
for s=0 to 4
do
enemyX[s]=rnd(608)
until enemyX[s]>32
enemyY[s]=-rnd(100)-32
next
for s=0 to 1
do
superenemyX[s]=rnd(608)
until superenemyX[s]>32
superenemyY[s]=-rnd(100)-32
next
endif
if bigexplox>0 and bigexplox<640 then
bigexplo_frame=bigexplo_frame+1
endif
if bigexplo_frame>6 then
bigexploactive=0
bigexplo_frame=0
bigexplox=-70
bigexploy=-70
lives=lives-1
planex=320
planey=480-128
health=100
endif
draw image bigexplo_frame+14,bigexplox,bigexploy

rem INFORMATION PANEL
rem =================
set color 220,220,220
draw rect 0,480-63,640,63,true
set color 180,180,180
draw rect 5,480-58,635,58,true
set color 120,120,120
draw rect 5,480-58,630,58,true
set color 0,0,255
draw rect 6,480-22,103,12
set color 0,0,0
draw rect 7,480-21,100,10,true
c=143
for z=1 to 10
set color 255,c,0
draw line 7,480-22+z,7+health,480-22+z
if i>5 then
c=c-44
else
c=c+44
endif
next
set caret 5,480-58
set color 0,0,0
write "Score:",score
set caret 5,480-48
write "Accuracy:",(float(bullseye)/float(shots_fired))*100.0,"%"
set color 255,255,255
for i=1 to lives
draw image 31, 120+i*32, 480-32
next
draw image 32,640-width(32),480-58

rem IF ALL LIVES ARE GONE, THEN IT`S GAME OVER
rem =========================================
if lives<0 then
for i=0 to 255
set color 0,0,0,i
draw rect 0,0,640,480,true
wait 10
redraw
next
break
endif

rem DRAWING EVERYTHNG AND WAITING
rem =============================
rem AND PAUSING THE GAME IF HIS MAJESTY WANTS SO
rem ============================================
if keydown("p",true) then
set color 0,0,0,128
draw rect 0,0,640,480,true
set color 255,255,255
set caret 640/2,480/2
center "PAUSE"
center "Press 'P' to continue"
redraw
do
wait 10
until keydown("p",true)
endif
redraw
wait 23
loop
if quit=1 then break
loop
