// Project: spaceinvaders
// Created: 2018-06-25
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "spaceinvaders" )
SetWindowSize( 640, 480, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 640, 480 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
// set the level to 1
global level=1
// define the fastenemy variable type. has to be outside of a function!
//Load the player spaceship sprite. Sprite no.1
Loadimage(1,"spaceship.png")
createsprite(1,1)
setspriteanimation (1,32,32,10)
Playsprite(1,5,1,1,2)
// create the variables for player
global Playerposy=450
global Playerposx=320
global shiphealth=3
global timetodead=10
// the enemies to go is set at 10 for level 1
Global enemiestogo=10
// make an array for up to 4 player bullets and set them to 0
dim playerbullet[4]
for i=1 to 4
playerbullet[i]=0
next i
// set level as 1
// Load player bullet sprites as over 100. create array with 3 pos. 1st is for exist, 2nd for x, 3rd for 7. Set 1st to 0 for all.
Global playerfire=0
global maxbullets=4
Global Dim BulletsXY[4,3]
// make an array for 4 bullets information. Info is bullets 1 to 4 , exist, x and y.
bulletsxy[1,1]=0
BulletsXY[2,1]=0
BulletsXY[3,1]=0
BulletsXY[4,1]=0
Loadimage (100,"playerbullet.png")
for i=0 to 3
createsprite (100+i,100)
setspritevisible(100+i,0)
next i
loadimage (200,"basicenemybullet.png")
// i used to have the total basic enemy bullets as 20. But i have just created 20 extras for the boss
for i=1 to 30
createsprite(200+i,200)
setspritevisible(200+i,0)
next i
// load enemy bullets as sprites over 200 (201-221) make array for basicenemybulletxy. 1st exist, 2nd x, 3rd Y
global Dim Basicenemyfire[10]
global Dim basicenemybulletxy[20,3]
// set enemy positions and load sprite
global enemyposx=50
Global enemyposy=10
global enemydiry=1
Global enemydirx=2
Global Dim basicenemy[10]
// set the left leader as 1 and the right leader as 10
global basicleftleader=1
global basicrightleader=10
Loadimage (2,"basicenemy.png")
for i=1 to 10
basicenemy[i]=1
createsprite (1+i,2)
Setspriteanimation (1+i,32,32,8)
Playsprite (1+i,5,1,1,2)
setspriteposition (1+i,enemyposx+(i*50),enemyposy)
next i
// new code for creating the fast enemy for level two. Create tge UDT fastenemy
// make an array fastenemies that is of the UDT type fastenemy. So each of the six slots in fastenemes as 5 slots, id, x y etc
type fastenemy
id as integer
x as float
y as float
exist as integer
fire as integer
endtype
Global dim fastenemies[] as fastenemy
Global _Spr_Fast as integer
_Spr_Fast = createSprite(loadimage("fastenemy.png"))
setSpriteVisible(_Spr_Fast, 0)
for i=1 to 6
fastenemies.insert (makefast(i))
next i
// Im positioning this fucntion close to the code for the creation of the the intial fastennemy.
function makefast(i as float)
n as fastenemy
n.x = 80 * i
n.y = 240
n.exist = 1
n.fire=0
n.id = CloneSprite(_Spr_Fast)
setSpriteVisible(n.id, 0)
setspritecollidebits(n.id,0)
setspriteactive(n.id,0)
setspriteanimation (n.id,32,32,8)
setspriteposition (n.id,n.x,n.y)
endfunction n
// lets create the fastenemy bullet array. They only fire once but they fire much more frequently than the other enemy type.
// array structure now a UDT with 4 variables. Firing is stored in the fastenemy UDT
// as fire.
type fastbullets
exist as integer
id as integer
x as float
y as float
endtype
global dim fastbulletsxy[fastenemies.length] as fastbullets
Global fastdirx=4
global fastposx=80
global fastleftleader=1
global fastrightleader=6
global _Spr_FastBullet as integer
_Spr_fastbullet=createsprite(loadimage("fastbullet.png"))
setSpriteVisible(_Spr_Fastbullet, 0)
for i=0 to fastenemies.length
fastbulletsxy[i].id=clonesprite(_Spr_FastBullet)
fastbulletsxy[i].exist=0
fastbulletsxy[i].x=80
fastbulletsxy[i].y=240
setspriteanimation (fastbulletsxy[i].id,12,12,3)
playsprite (fastbulletsxy[i].id,5,1,1,3)
setspritevisible (fastbulletsxy[i].id,0)
setspritecollidebits (fastbulletsxy[i].id,0)
next i
// loadthe image and create the boss of level 3
type bossenemy
id as integer
x as float
y as float
movepattern as integer
exist as integer
fire as integer
bomb as integer
resurrect as integer
endtype
global _spr_boss as integer
_spr_boss=createsprite(loadimage("boss.png"))
global dim boss[1] as bossenemy
boss[1].id=_spr_boss
boss[1].x=260
boss[1].y=40
boss[1].exist=1
boss[1].fire=0
boss[1].bomb=0
boss[1].resurrect=0
boss[1].movepattern=1
setspriteanimation (boss[1].id,96,96,21)
playsprite (boss[1].id,5,1,1,1)
setspriteactive (boss[1].id,0)
setspritevisible (boss[1].id,0)
SetSpriteCollideBits (boss[1].id,0)
// set the maximum amount of bullets for the boss as 20
global dim bossbulletsxy[20] as fastbullets
for i=1 to 20
bossbulletsxy[i].exist=0
bossbulletsxy[i].x=0
bossbulletsxy[i].y=0
bossbulletsxy[i].id=clonesprite(_spr_fastbullet)
setspriteanimation (bossbulletsxy[i].id,12,12,3)
playsprite (bossbulletsxy[i].id,5,1,1,3)
setspriteactive(bossbulletsxy[i].id,0)
SetSpriteVisible(bossbulletsxy[i].id,0)
SetSpriteCollideBits(bossbulletsxy[i].id,0)
next i
// create an array for the bomb. Everything is using the fastbullets data type now
global dim bossbombxy[1] as fastbullets
bossbombxy[1].exist=0
bossbombxy[1].x=0
bossbombxy[1].y=0
bossbombxy[1].id=createsprite(loadimage("bomb.png"))
setspriteactive (bossbombxy[1].id,0)
SetSpriteVisible(bossbombxy[1].id,0)
SetSpriteCollideBits(bossbombxy[1].id,0)
//create the variables for the boss directional movement
global bossdirx=5
global bossdiry=2
global bosshealth=100
// lets use sprites 221-230 as my basicbossbullets
global dim basicbossbulletsxy[10] as fastbullets
for i=1 to 10
basicbossbulletsxy[i].exist=0
basicbossbulletsxy[i].id=220+i
basicbossbulletsxy[i].x=0
basicbossbulletsxy[i].y=0
next i
level=1
buildlevel ()
do
inputs ()
enemies ()
playerbullets ()
enemiesbullets ()
player()
Print( ScreenFPS() )
Sync()
loop
function buildlevel ()
if level=1
// reset player sprite animation and variables and playerbullet array
Playsprite(1,5,1,1,2)
Playerposy=450
Playerposx=320
shiphealth=3
timetodead=10
for i=1 to 4
playerbullet[i]=0
next i
// Set playerfire equal to 0 and bullets equal to 0. Set bullets invisible
playerfire=0
maxbullets=4
bulletsxy[1,1]=0
BulletsXY[2,1]=0
BulletsXY[3,1]=0
BulletsXY[4,1]=0
for i=0 to 3
setspritevisible(100+i,0)
next i
// set enemy bullets to invisible
for i=1 to 20
setspritevisible(200+i,0)
next i
// reset enemy positions, direction and set total enemies to kill at 10
enemyposx=50
enemyposy=10
enemydirx=2
enemiestogo=10
// set the left leader as 1 and the right leader as 10
basicleftleader=1
basicrightleader=10
// reset the animations of enemies and reposition
for i=1 to 10
basicenemy[i]=1
Setspriteanimation (1+i,32,32,8)
Playsprite (1+i,5,1,1,2)
setspriteposition (1+i,enemyposx+(i*50),enemyposy)
setspritevisible(1+i,1)
SetSpriteActive (1+i,1)
next i
endif
if level=2
// reset player sprite animation and variables and playerbullet array
setspriteanimation (1,32,32,10)
Playsprite(1,5,1,1,2)
Playerposy=450
Playerposx=320
shiphealth=3
timetodead=10
for i=1 to 4
playerbullet[i]=0
next i
// Set playerfire equal to 0 and bullets equal to 0. Set bullets invisible
playerfire=0
maxbullets=4
bulletsxy[1,1]=0
BulletsXY[2,1]=0
BulletsXY[3,1]=0
BulletsXY[4,1]=0
for i=0 to 3
setspritevisible(100+i,0)
next i
// set enemy bullets to invisible
for i=1 to 20
setspritevisible(200+i,0)
next i
// reset enemy positions, direction and set total enemies to kill at 10
enemyposx=50
enemyposy=10
enemydirx=2
enemiestogo=16
// set the left leader as 1 and the right leader as 10
basicleftleader=1
basicrightleader=10
// reset the animations of enemies and reposition
for i=1 to 10
basicenemy[i]=1
Setspriteanimation (1+i,32,32,8)
Playsprite (1+i,5,1,1,2)
setspriteposition (1+i,enemyposx+(i*50),enemyposy)
setspritevisible(1+i,1)
SetSpriteActive (1+i,1)
next i
// lets reset the fast enemies for level 2
for i=0 to fastenemies.length
setSpriteVisible(fastenemies[i].id, 1)
setspriteanimation (fastenemies[i].id,32,32,8)
setspriteactive (fastenemies[i].id,1)
fastbulletsxy[i].exist=0
playsprite(fastenemies[i].id,5,1,1,1)
fastenemies[i].exist=1
fastbulletsxy[i].x=80
fastbulletsxy[i].y=240
next i
fastdirx=4
fastposx=80
fastleftleader=1
fastrightleader=6
endif
if level=3
// set the boss to active
setspriteactive (boss[1].id,1)
setspritevisible (boss[1].id,1)
SetSpriteCollideBits (boss[1].id,1)
bossdirx=5
bossdiry=2
boss[1].exist=1
// reset player sprite animation and variables and playerbullet array
setspriteanimation (1,32,32,10)
Playsprite(1,5,1,1,2)
setspriteposition(boss[1].id,boss[1].x,boss[1].y)
Playerposy=450
Playerposx=320
shiphealth=3
timetodead=10
for i=1 to 4
playerbullet[i]=0
next i
// Set playerfire equal to 0 and bullets equal to 0. Set bullets invisible
playerfire=0
maxbullets=4
bulletsxy[1,1]=0
BulletsXY[2,1]=0
BulletsXY[3,1]=0
BulletsXY[4,1]=0
for i=0 to 3
setspritevisible(100+i,0)
next i
// set enemy bullets to invisible
for i=1 to 20
setspritevisible(200+i,0)
next i
// reset enemy positions, direction. Basics spawn at 200y now.
enemyposx=50
enemyposy=10
enemydirx=2
enemiestogo=1
// set the left leader as 1 and the right leader as 10
basicleftleader=1
basicrightleader=10
// reset the animations of enemies and reposition. But make invisible due to not being ressurected
for i=1 to 10
basicenemy[i]=0
Setspriteanimation (1+i,32,32,8)
Playsprite (1+i,5,1,1,2)
setspriteposition (1+i,enemyposx+(i*50),enemyposy)
setspritevisible(1+i,0)
SetSpriteActive (1+i,0)
next i
// lets reset the fast enemies for a level 3 design
for i=0 to fastenemies.length
setSpriteVisible(fastenemies[i].id, 0)
setspriteanimation (fastenemies[i].id,32,32,8)
setspriteactive (fastenemies[i].id,0)
fastbulletsxy[i].exist=0
playsprite(fastenemies[i].id,5,1,1,1)
fastenemies[i].exist=0
fastbulletsxy[i].x=80
fastbulletsxy[i].y=240
next i
fastdirx=4
fastposx=80
fastleftleader=1
fastrightleader=6
endif
Endfunction
function inputs ()
playerfire=0
if getrawkeystate(37)=1 then playerposx=playerposx-5
if getrawkeystate(39)=1 then playerposx=playerposx+5
if getrawkeystate(40)=1 then playerposy=playerposy+5
if getrawkeystate(38)=1 then playerposy=playerposy-5
if getrawkeypressed (32)=1 then playerfire=1
setspriteposition (1,playerposx,playerposy)
endfunction
function enemies ()
enemyposx=enemyposx+enemydirx
// check enemy direction. If heading to right, check if the right leader is anyone but the most left basicenemy.
// run a collision to the right wall. If it is the most left enemy as the right leader, run a different collision.
// this is reversed for the left leader.
if enemydirx=2
if basicrightleader>1
if enemyposx+(basicrightleader*50)>600
enemyposx=enemyposx-2
enemydirx=-2
enemyposy=enemyposy+enemydiry
endif
elseif basicrightleader=1
if enemyposx>600
enemyposx=600
enemydirx=-2
enemyposy=enemyposy+enemydiry
endif
endif
endif
if enemyposy>230
enemydiry=-10
endif
if enemyposy<30
enemydiry=10
endif
if enemydirx=-2
if basicleftleader>1
if enemyposx+(basicleftleader*50)<10
enemyposx=enemyposx+2
enemydirx=2
enemyposy=enemyposy+enemydiry
endif
elseif basicleftleader=1
if enemyposx<-10
enemyposx=-10
enemydirx=2
enemyposy=enemyposy+enemydiry
endif
Endif
endif
// Draw sprites 2 to 11 if they exist. Check if sprite killed was leader. If so, search for next sprite in line and make leader
for i=1 to 10
if basicenemy[i]>-1
if basicenemy[i]=0
setspriteposition (1+i,enemyposx+(i*50),enemyposy)
if GetSpriteCurrentFrame (1+i)=8
basicenemy[i]=-1
enemiestogo=enemiestogo-1
if basicleftleader<basicrightleader
if basicleftleader=i
if basicenemy[i]<0
if basicleftleader<10
while basicenemy[basicleftleader]<>1 and basicleftleader<10
basicleftleader=basicleftleader+1
endwhile
endif
endif
endif
if basicrightleader=i
if basicenemy[i]<0
if basicrightleader>1
while basicenemy[basicrightleader]<>1 and basicrightleader>1
basicrightleader=basicrightleader-1
endwhile
endif
endif
endif
endif
setspritevisible(i+1,0)
SetSpriteCollideBits(i+1,0)
setspriteactive(i+1,0)
endif
endif
if basicenemy[i]=1 then setspriteposition (1+i,enemyposx+(i*50),enemyposy)
if basicenemy[i]=2
setspriteposition (1+i,enemyposx+(i*50),enemyposy)
if GetSpriteCurrentFrame(i+1)=2
playsprite (i+1,5,1,1,2)
Basicenemy[i]=1
endif
endif
endif
next i
// check if level is greater than 1, then do the movement behaviours for the fast enemies.
if level>1
fastposx=fastposx+fastdirx
// check enemy direction. If heading to right, check if the right leader is anyone but the most left basicenemy.
// run a collision to the right wall. If it is the most left enemy as the right leader, run a different collision.
// this is reversed for the left leader.
if fastdirx=4
if fastrightleader>1
if fastposx+(fastrightleader*80)>630
fastposx=fastposx-4
fastdirx=-4
endif
elseif fastrightleader=1
if fastposx>630
fastposx=630
fastdirx=-4
endif
endif
endif
if fastdirx=-4
if fastleftleader>1
if fastposx+(fastleftleader*80)<30
fastposx=fastposx+4
fastdirx=4
endif
elseif fastleftleader=1
if fastposx<30
fastposx=30
fastdirx=4
endif
Endif
endif
// draw fastenemy sprites and check for leader based on length of array.
for i=0 to fastenemies.length
if fastenemies[i].exist>-1
if fastenemies[i].exist=0
setspriteposition (fastenemies[i].id,fastposx+(80*i),240)
if GetSpriteCurrentFrame (fastenemies[i].id)=8
fastenemies[i].exist=-1
enemiestogo=enemiestogo-1
if fastleftleader<fastrightleader
if fastleftleader=i
if fastenemies[i].id<0
if fastleftleader<5
while fastenemies[fastleftleader].exist<>1 and fastleftleader<5
fastleftleader=fastleftleader+1
endwhile
endif
endif
endif
if fastrightleader=i
if fastenemies[i].exist<0
if fastrightleader>1
while fastenemies[basicrightleader].exist<>1 and fastrightleader>1
fastrightleader=fastrightleader-1
endwhile
endif
endif
endif
endif
setspritevisible(fastenemies[i].id,0)
SetSpriteCollideBits(fastenemies[i].id,0)
setspriteactive(fastenemies[i].id,0)
endif
endif
if fastenemies[i].exist=1
setspriteposition (fastenemies[i].id,fastposx+(80*i),240)
endif
endif
next i
endif
if level=3
movementchance=random(1,200)
if movementchance=5
boss[1].movepattern=random(1,4)
endif
if boss[1].movepattern=1 //movepattern 1 is down right
bossdirx=5
bossdiry=2
endif
if boss[1].movepattern=2 // movepattern 2 is up left
bossdirx=-5
bossdiry=-2
endif
if boss[1].movepattern=3 // movepattern 3 is up right
bossdirx=5
bossdiry=-2
endif
if boss[1].movepattern=4 // movepattern 4 is down left
bossdirx=-5
bossdiry=2
endif
boss[1].x=boss[1].x+bossdirx
Boss[1].y=boss[1].y+bossdiry
if boss[1].x>538
boss[1].x=538
if boss[1].movepattern=1 then boss[1].movepattern=4
if boss[1].movepattern=3 then boss[1].movepattern=2
endif
if boss[1].x<10
boss[1].x=10
if boss[1].movepattern=4 then boss[1].movepattern=1
if boss[1].movepattern=2 then boss[1].movepattern=3
endif
if boss[1].y<10
boss[1].y=10
if boss[1].movepattern=2 then boss[1].movepattern=4
if boss[1].movepattern=3 then boss[1].movepattern=1
endif
If boss[1].y>200
boss[1].y=200
if boss[1].movepattern=4 then boss[1].movepattern=2
if boss[1].movepattern=1 then boss[1].movepattern=3
endif
setspriteposition (boss[1].id,boss[1].x,boss[1].y)
if boss[1].exist=1
if bosshealth<1 then boss[1].exist=0
endif
print ("BOSS HEALTH")
print (bosshealth)
if boss[1].exist=0
playsprite(boss[1].id,5,1,13,21)
boss[1].exist=-1
endif
if boss[1].exist=-1
if getspritecurrentframe(boss[1].id)=21
boss[1].exist=-2
setspritevisible (boss[1].id,0)
level=4
levelup()
endif
endif
endif
If level<3
if enemiestogo<1 then levelup()
endif
print ("Enemies left to destroy")
print (enemiestogo)
print ("fast x and left and right")
print (fastposx)
print (fastleftleader)
print (fastrightleader)
endfunction
function playerbullets ()
if playerfire=1
if BulletsXY[1,1]=0
bulletsxy[1,1]=1
Bulletsxy[1,2]=playerposx+12
bulletsxy[1,3]=playerposy-16
setspritevisible(100,1)
elseif bulletsxy[1,1]=1
if bulletsxy[2,1]=0
Bulletsxy[2,1]=1
Bulletsxy[2,2]=playerposx+12
bulletsxy[2,3]=playerposy-16
setspritevisible(101,1)
elseif bulletsxy[2,1]=1
if bulletsxy[3,1]=0
bulletsxy[3,1]=1
bulletsxy[3,2]=playerposx+12
bulletsxy[3,3]=playerposy-16
setspritevisible(102,1)
elseif bulletsxy[3,1]=1
if bulletsxy[4,1]=0
bulletsxy[4,1]=1
bulletsxy[4,2]=playerposx+12
bulletsxy[4,3]=playerposy-16
setspritevisible(103,1)
endif
endif
endif
endif
endif
for i=1 to 4
if bulletsxy[i,1]=1
bulletsxy[i,3]=bulletsxy[i,3]-8
if bulletsxy[i,3]<5
bulletsxy[i,1]=0
setspritevisible(99+i,0)
endif
setspriteposition(99+i,bulletsxy[i,2],bulletsxy[i,3])
// check for collisions, c is sprites 2 to 11 (the numbers of your enemies) i is still 1 to 4
// the numbers of your bullets. Bullet sprites are 100 to 103 hence 99+i
for c=2 to 11
if basicenemy[c-1]=1
if getspritecollision(c,99+i)=1
basicenemy[c-1]=0
bulletsxy[i,1]=0
setspritevisible(i+99,0)
playsprite (c,5,1,3,8)
endif
endif
next c
if level=2
for f=0 to 5
if fastenemies[f].exist=1
if GetSpriteCollision(fastenemies[f].id,99+i)=1
fastenemies[f].exist=0
bulletsxy[i,1]=0
setspritevisible(i+99,0)
playsprite (fastenemies[f].id,5,1,2,8)
endif
endif
next f
endif
if level=3
if boss[1].exist=1
if bulletsxy[i,1]=1
if GetSpriteCollision(boss[1].id,99+i)=1
bosshealth=bosshealth-1
bulletsxy[i,1]=0
setspritevisible(i+99,0)
endif
endif
endif
endif
endif
next i
endfunction
function enemiesbullets ()
// make a 1 in 100 chance of enemy firing per sync rate.
for i=1 to 10
bulletchance=random(1,100)
if bulletchance=5
if basicenemy[i]=1
if basicenemybulletxy[i,1]=0
basicenemyfire[i]=1
endif
endif
endif
next i
// basicenemybulletxy is a 20 x 3 array. 1 for exist, 2 for x and 3 for y
for i=1 to 10
if basicenemyfire[i]=1
basicenemyfire[i]=0
if basicenemybulletxy[i,1]=0
basicenemybulletxy[i,1]=1
basicenemybulletxy[i,2]=getspritex(i+1)-12
basicenemybulletxy[i,3]=getspritey(i+1)+16
setspritevisible (200+i,1)
basicenemybulletxy[i+10,1]=1
basicenemybulletxy[i+10,2]=getspritex(i+1)+12
basicenemybulletxy[i+10,3]=getspritey(i+1)+16
setspritevisible (210+i,1)
endif
endif
next i
// bullets are shot in pairs, first checks for right moving and second for left moving
for i=1 to 10
if basicenemybulletxy[i,1]=1
basicenemybulletxy[i,3]=basicenemybulletxy[i,3]+5
basicenemybulletxy[i,2]=basicenemybulletxy[i,2]-1
if basicenemybulletxy[i,3]>475
basicenemybulletxy[i,1]=0
setspritevisible(200+i,0)
endif
setspriteposition(200+i,basicenemybulletxy[i,2],basicenemybulletxy[i,3])
If getspritevisible(200+i)=1
if getspritecollision(200+i,1)=1
Shiphealth=shiphealth-1
basicenemybulletxy[i,1]=0
setspritevisible(200+i,0)
endif
endif
endif
if basicenemybulletxy[i+10,1]=1
basicenemybulletxy[i+10,3]=basicenemybulletxy[i+10,3]+5
basicenemybulletxy[i+10,2]=basicenemybulletxy[i+10,2]+1
if basicenemybulletxy[i+10,3]>475
basicenemybulletxy[i+10,1]=0
setspritevisible(200+i+10,0)
endif
setspriteposition(200+i+10,basicenemybulletxy[i+10,2],basicenemybulletxy[i+10,3])
If getspritevisible(210+i)=1
if getspritecollision(210+i,1)=1
Shiphealth=shiphealth-1
basicenemybulletxy[i+10,1]=0
setspritevisible(210+i,0)
endif
endif
endif
next i
if level>1
for i=0 to fastenemies.length
bulletchance=random(1,50)
if bulletchance=5
if fastenemies[i].exist=1
if fastbulletsxy[i].exist=0
fastenemies[i].fire=1
endif
endif
endif
next i
// fastbulletsxy is a UDT with exist, id, x and y Fire is located in fastenemies UDT
for i=0 to fastenemies.length
if fastenemies[i].fire=1
fastenemies[i].fire=0
if fastbulletsxy[i].exist=0
fastbulletsxy[i].exist=1
fastbulletsxy[i].x=getspritex(fastenemies[i].id)-12
fastbulletsxy[i].y=getspritey(fastenemies[i].id)+16
setspritevisible (fastbulletsxy[i].id,1)
endif
endif
// this next bit moves the bullet
if fastbulletsxy[i].exist=1
fastbulletsxy[i].y=fastbulletsxy[i].y+6
if fastbulletsxy[i].y>475
fastbulletsxy[i].exist=0
setspritevisible(fastbulletsxy[i].id,0)
endif
setspriteposition(fastbulletsxy[i].id,fastbulletsxy[i].x,fastbulletsxy[i].y)
If getspritevisible(fastbulletsxy[i].id)=1
if getspritecollision(fastbulletsxy[i].id,1)=1
Shiphealth=shiphealth-1
fastbulletsxy[i].exist=0
setspritevisible(fastbulletsxy[i].id,0)
endif
endif
endif
next i
endif
if level=3
print ("fire bomb res")
print (boss[1].fire)
print (boss[1].bomb)
print (boss[1].resurrect)
if boss[1].exist=1
if boss[1].resurrect=0
if boss[1].fire=0
if boss[1].bomb=0
playsprite(boss[1].id,5,1,6,6)
bulletchance=random(1,50)
if bulletchance<11 then boss[1].fire=1
if bulletchance<15 and bulletchance>10 then boss[1].resurrect=1
if bulletchance>14 and bulletchance<20
if bossbombxy[1].exist=0 then boss[1].bomb=1
endif
endif
endif
endif
if boss[1].resurrect=1
playsprite(boss[1].id,5,0,1,5)
boss[1].resurrect=2
endif
if boss[1].resurrect=2
if getspritecurrentframe(boss[1].id)=5
i=random(1,10)
if basicenemy[i]<1
basicenemy[i]=2
for basicleftleader=1 to i
if basicenemy[basicleftleader]>0
exit
endif
next basicleftleader
for basicrightleader=10 to i
if basicenemy[basicrightleader]>0
exit
endif
next basicrightleader
setspriteactive(i+1,1)
setspritevisible(i+1,1)
playsprite(i+1,5,1,7,2)
boss[1].resurrect=0
playsprite(boss[1].id,5,1,1,1)
else
boss[1].resurrect=0
playsprite(boss[1].id,5,1,1,1)
for i=1 to 5
if basicbossbulletsxy[i].exist=0
basicbossbulletsxy[i].exist=1
basicbossbulletsxy[i].x=getspritex(boss[1].id)-30
basicbossbulletsxy[i].y=getspritey(boss[1].id)+50
setspritevisible (basicbossbulletsxy[i].id,1)
exit
endif
next i
for i=6 to 10
if basicbossbulletsxy[i].exist=0
basicbossbulletsxy[i].exist=1
basicbossbulletsxy[i].x=getspritex(boss[1].id)+30
basicbossbulletsxy[i].y=getspritey(boss[1].id)+50
setspritevisible (basicbossbulletsxy[i].id,1)
exit
endif
next i
endif
endif
endif
for i=1 to 5
if basicbossbulletsxy[i].exist=1
basicbossbulletsxy[i].y=basicbossbulletsxy[i].y+3
basicbossbulletsxy[i].x=basicbossbulletsxy[i].x-2
setspriteposition(basicbossbulletsxy[i].id,basicbossbulletsxy[i].x,basicbossbulletsxy[i].y)
if basicbossbulletsxy[i].y>475
basicbossbulletsxy[i].y=0
basicbossbulletsxy[i].exist=0
setspritevisible(basicbossbulletsxy[i].id,0)
endif
if getspritecollision(basicbossbulletsxy[i].id,1)=1
shiphealth=shiphealth-1
setspritevisible(basicbossbulletsxy[i].id,0)
basicbossbulletsxy[i].exist=0
endif
endif
next i
for i=6 to 10
if basicbossbulletsxy[i].exist=1
basicbossbulletsxy[i].y=basicbossbulletsxy[i].y+3
basicbossbulletsxy[i].x=basicbossbulletsxy[i].x+2
setspriteposition(basicbossbulletsxy[i].id,basicbossbulletsxy[i].x,basicbossbulletsxy[i].y)
if basicbossbulletsxy[i].y>475
basicbossbulletsxy[i].y=0
basicbossbulletsxy[i].exist=0
setspritevisible(basicbossbulletsxy[i].id,0)
endif
if getspritecollision(basicbossbulletsxy[i].id,1)=1
shiphealth=shiphealth-1
setspritevisible(basicbossbulletsxy[i].id,0)
basicbossbulletsxy[i].exist=0
endif
endif
next i
if boss[1].bomb=1
boss[1].fire=0
boss[1].resurrect=0
boss[1].bomb=2
PlaySprite(boss[1].id,5,1,8,12)
endif
if boss[1].bomb=2
if getspritecurrentframe(boss[1].id)=12
boss[1].bomb=0
playsprite(boss[1].id,5,1,6,6)
bossbombxy[1].exist=1
bossbombxy[1].x=getspritex(boss[1].id)+46
bossbombxy[1].y=getspritey(boss[1].id)+65
setspritevisible (bossbombxy[1].id,1)
endif
endif
if bossbombxy[1].exist=1
if bossbombxy[1].x<playerposx then bossbombxy[1].x=bossbombxy[1].x+3
if bossbombxy[1].x>playerposx then bossbombxy[1].x=bossbombxy[1].x-3
bossbombxy[1].y=bossbombxy[1].y+5
setspriteposition(bossbombxy[1].id,bossbombxy[1].x,bossbombxy[1].y)
if bossbombxy[1].y>450
bossbombxy[1].exist=0
setspritevisible (bossbombxy[1].id,0)
boss[1].bomb=0
boss[1].fire=0
boss[1].resurrect=0
endif
if getspritecollision(1,bossbombxy[1].id)=1
shiphealth=shiphealth-3
bossbombxy[1].exist=0
setspritevisible(bossbombxy[1].id,0)
endif
endif
if boss[1].fire=1
playsprite(boss[1].id,5,1,7,7)
boss[1].fire=0
for i=1 to bossbulletsxy.length
if bossbulletsxy[i].exist=0
bossbulletsxy[i].exist=1
bossbulletsxy[i].x=getspritex(boss[1].id)+46
bossbulletsxy[i].y=getspritey(boss[1].id)+65
setspritevisible (bossbulletsxy[i].id,1)
i=bossbulletsxy.length
endif
next i
endif
for i=1 to bossbulletsxy.length
if bossbulletsxy[i].exist=1
bossbulletsxy[i].y=bossbulletsxy[i].y+6
if bossbulletsxy[i].y>475
bossbulletsxy[i].exist=0
setspritevisible(bossbulletsxy[i].id,0)
endif
setspriteposition(bossbulletsxy[i].id,bossbulletsxy[i].x,bossbulletsxy[i].y)
If getspritevisible(bossbulletsxy[i].id)=1
if getspritecollision(bossbulletsxy[i].id,1)=1
Shiphealth=shiphealth-1
bossbulletsxy[i].exist=0
setspritevisible(bossbulletsxy[i].id,0)
endif
endif
endif
next i
endif
endif
Print ("shiphealth")
Print (shiphealth)
endfunction
function player ()
If shiphealth=0
shiphealth=-1
playsprite (1,5,1,2,10)
Timetodead=52
endif
If shiphealth<0
Timetodead=Timetodead-1
endif
if timetodead<-1 then playagain()
endfunction
Function playagain()
setspritevisible (1,0)
while getrawkeypressed (32)=0
if level<4 then Print ("You are dead, press spacebar to try again at Level 1")
sync ()
Endwhile
if level=2
for i=0 to fastenemies.length
setspritevisible (fastenemies[i].id,0)
setspritecollidebits (fastenemies[i].id,0)
fastenemies[i].exist=0
next i
for i=0 to fastbulletsxy.length
setspritevisible (fastbulletsxy[i].id,0)
fastbulletsxy[i].exist=0
next i
endif
if level=3
setspritevisible(boss[1].id,0)
boss[1].exist=0
bossbombxy[1].exist=0
setspritevisible(bossbombxy[1].id,0)
for i=1 to bossbulletsxy.length
bossbulletsxy[i].exist=0
setspritevisible(bossbulletsxy[i].id,0)
next i
for i=1 to basicbossbulletsxy.length
basicbossbulletsxy[i].exist=0
setspritevisible(basicbossbulletsxy[i].id,0)
next i
endif
shiphealth=3
setspritevisible (1,1)
timetodead=10
level=1
bosshealth=100
buildlevel()
Endfunction
Function levelup ()
while getrawkeypressed (32)=0
if level=1 then Print ("Congratulations, you destroyed the invaders. Press spacebar to try next level")
if level=2 then print ("Nice, you beat the 2 types of enemies. Press spacebar to play agains the boss")
if level=4 then print ("nice you beat the boss, demo over, press space to start again at level 1")
sync ()
Endwhile
if level=4
bosshealth=100
level=0
setspritevisible(boss[1].id,0)
boss[1].exist=0
bossbombxy[1].exist=0
setspritevisible(bossbombxy[1].id,0)
for i=1 to bossbulletsxy.length
bossbulletsxy[i].exist=0
setspritevisible(bossbulletsxy[i].id,0)
next i
for i=1 to basicbossbulletsxy.length
basicbossbulletsxy[i].exist=0
setspritevisible(basicbossbulletsxy[i].id,0)
next i
endif
shiphealth=3
timetodead=10
level=level+1
buildlevel()
Endfunction
Hello everyone. So there it is. My second project with AppGameKit is finished. Or as finished as I want to go I think I've learnt what I wanted to learn. It's interesting you can see how the naming of variables changed as I listened to people in the thread, and the way collision detection and everything is handled after learning about UDTs. Thanks everyone for your help, the next thing I want to make is an infinity runner, this one I want to be downloadable and playable on phones so I will give it a main menu and highscore and all that.
See you on the next project