Should be the last and final post of this one
SetVirtualResolution(1024,768)
SetWindowSize( 1024, 768, 0 )
SetOrientationAllowed( 0, 0, 1, 1 )
GLOBAL stars as integer[10,10]
GLOBAL mapHeight as integer
GLOBAL mapWidth as integer
GLOBAL radar as integer
type bullettype
id as integer
x as float
y as float
angle as float
count as integer
endtype
type enemyType
id as integer
angle as float
image as integer
count as integer
velocity as float
hitpoints as integer
enemybullets as bullettype[5]
gone as integer
x as float
y as float
endtype
GLOBAL enemyFighter as enemyType[10]
//GLOBAL radarSprites as integer [16]
GLOBAL spaceStations as enemyType[5]
type shipType
id as integer
score as integer
lives as integer
velocity as float
endtype
GlOBAL playerShip as shipType
GLOBAL highscore as integer
GLOBAL map as integer
GLOBAL level as integer
GLOBAL spacestationCounter as integer
highscore=0
dim playerBullets[10,2] as bullettype
//loadSprites(loadMap ("map.txt"))
SetRawMousePosition(GetVirtualWidth()/2,GetVirtualHeight()/2)
flag=0
GLOBAL explosionImage =70
loadMenu():showMenu()
do
if ( GetPointerPressed ( ) = 1 )
hit = GetSpriteHit ( GetPointerX ( ), GetPointerY ( ) )
select hit
case 501:
hideMenu()
map=1:level=1:spacestationCounter=5
levelColor$=loadMap ("map"+str(map)+".txt")
advanceLevel(levelColor$)
loadSprites(levelColor$)
playerShip.score=0
playerShip.lives=3
resetShips()
playGame()
endcase
case 502:
hideMenu()
showRules()
showMenu()
endcase
case 503:
end
endcase
endselect
endif
Sync ()
loop
function playGame()
do
scrollSprites()
displayScore()
If playerShip.lives <1
SetSpriteVisible(playerShip.id,0)
gameover()
loadMenu()
showMenu()
SetSpriteVisible(playerShip.id,1)
exitfunction
endif
if spacestationCounter <=0
inc level
inc map
if map > 4 then map =1
levelColor$=loadMap ("map"+str(map)+".txt")
advanceLevel(levelColor$)
loadSprites(levelColor$)
spacestationCounter=5
resetShips()
endif
//print(screenFPS())
sync()
loop
setSpriteVisible(501,1)
setSpriteVisible(502,1)
setSpriteVisible(503,1)
endfunction
function loadMenu()
LoadImage(500,"title.png")
LoadImage(501,"playGame.png")
LoadImage(502,"rules.png")
LoadImage(503,"exitGame.png")
CreateSprite(500,500)
CreateSprite(501,501)
CreateSprite(502,502)
CreateSprite(503,503)
SetSpriteDepth(500,0)
SetSpriteDepth(501,0)
SetSpriteDepth(502,0)
SetSpriteDepth(503,0)
SetSpriteOffset(500,GetImageWidth(500)/2,0)
SetSpritePositionByOffset(500,GetVirtualWidth()/2,0)
SetSpriteOffset(501,GetImageWidth(501)/2,0)
SetSpritePositionByOffset(501,GetVirtualWidth()/2,150)
SetSpriteOffset(502,GetImageWidth(502)/2,0)
SetSpritePositionByOffset(502,GetVirtualWidth()/2,300)
SetSpriteOffset(503,GetImageWidth(503)/2,0)
SetSpritePositionByOffset(503,GetVirtualWidth()/2,450)
endfunction
function showRules()
SetSpriteVisible(500,0)
LoadImage(504,"rules2.png")
createSprite(504,504)
SetSpritePosition(504,0,0)
flag=1:sync()
while flag=1
if getpointerpressed()=1
flag=0
endif
sync()
endwhile
deleteSprite(504)
deleteImage(504)
SetSpriteVisible(500,1)
endfunction
function showMenu()
setSpriteVisible(playerShip.id,0)
setSpriteVisible(501,1)
setSpriteVisible(502,1)
setSpriteVisible(503,1)
endfunction
function hideMenu()
setSpriteVisible(playerShip.id,1)
setSpriteVisible(501,0)
setSpriteVisible(502,0)
setSpriteVisible(503,0)
endfunction
function drawRadar()GetSpriteOffsetX(spaceStations[num].id)/mapWidth)*100.0
print (mapWidth)
for num = 1 to 5
x#=(GetSpriteXByOffset(spaceStations[num].id)/mapWidth)
x#=x#*(GetImageWidth(radar))+(1024-132)
y#=(GetSpriteYByOffset(spaceStations[num].id)/mapHeight)
y#=y#*GetImageHeight(radar)+(768-102)
//print (x#)
//print (y#)
//SetSpritePosition(radarSprites[num],x#,y#)
next num
endfunction
function loadSprites(enemy as string)
DeleteAllSprites()
DeleteAllImages()
DeleteAllText()
LoadImage(500,"title.png")
CreateSprite(500,500)
SetSpriteOffset(500,GetImageWidth(500)/2,0)
SetSpritePositionByOffset(500,GetVirtualWidth()/2,0)
explosionImage = LoadImage ("explosion.png")
select enemy
case "green":
LoadImage(100,"spacestation.png")
LoadImage(101,"greenship1.png")
LoadImage(102,"greenship2.png")
LoadImage(103,"spritegrn.png")
endcase
case "blue":
LoadImage(100,"spacestationblue.png")
LoadImage(101,"blueship1.png")
LoadImage(102,"blueship2.png")
LoadImage(103,"spriteblue.png")
endcase
case "red"
LoadImage(100,"spacestationred.png")
LoadImage(101,"redship1.png")
LoadImage(102,"redship2.png")
LoadImage(103,"spritered.png")
endcase
case "gold"
LoadImage(100,"goldspacestation.png")
LoadImage(101,"goldship1.png")
LoadImage(102,"goldship2.png")
LoadImage(103,"spritegold.png")
endcase
endselect
LoadImage(1,"fighter2.png")
LoadImage(2,"radar.png")
for y = 1 to 10
for x = 1 to 10
stars[x,y] = createSprite(0)
setSpriteSize(stars[x,y],2,2)
setSpritePosition(stars[x,y],random(1,1024),random(1,768))
setSpriteColor(stars[x,y],random(1,255),random(1,255),random(1,255),255)
next x
next y
for num = 1 to 5
createSprite(spaceStations[num].id,spaceStations[num].image)
if (spaceStations[num].image=100)
SetSpriteOffset(spaceStations[num].id,256,256)
else
SetSpriteOffset(spaceStations[num].id,64,128)
endif
SetSpritePositionByOffset(spaceStations[num].id,spaceStations[num].x,spaceStations[num].y)
//radarSprites[num]=CreateSprite(0)
//SetSpriteSize(radarSprites[num],10,10)
//SetSpriteColor(radarSprites[num],0,150,0,255)
//SetSpriteDepth(radarSprites[num],0)
next num
temp=300
for num = 1 to 10
enemyFighter[num].id=199+num
enemyFighter[num].count=(num-1)*100
enemyFighter[num].velocity=0
createSprite(enemyFighter[num].id,103)
enemyFighter[num].x=GetSpriteXByOffset(spaceStations[3].id):rem+224
enemyFighter[num].y=GetSpriteYByOffset(spaceStations[3].id):rem+192
SetSpriteOffset(enemyFighter[num].id,32,64)
SetSpritePositionByOffset(enemyFighter[num].id,enemyFighter[num].x,enemyFighter[num].y)
SetSpriteDepth(enemyFighter[num].id,2)
for bullets=1 to 5
//Front shooting enemy bullets
enemyFighter[num].enemybullets[bullets].id=temp
createSprite(enemyFighter[num].enemybullets[bullets].id,0)
enemyFighter[num].enemybullets[bullets].x=0
enemyFighter[num].enemybullets[bullets].y=0
enemyFighter[num].enemybullets[bullets].angle=0
enemyFighter[num].enemybullets[bullets].count=(num-1)*20
SetSpritePositionByOffset(enemyFighter[num].enemybullets[bullets].id,enemyFighter[num].enemybullets[bullets].x,enemyFighter[num].enemybullets[bullets].y)
setSpriteSize(enemyFighter[num].enemybullets[bullets].id,4,4)
SetSpriteDepth(enemyFighter[num].enemybullets[bullets].id,1)
setSpriteColor(enemyFighter[num].enemybullets[bullets].id,255,255,255,255)
inc temp
next bullets
//radarSprites[num+5]=CreateSprite(0)
//SetSpriteSize(radarSprites[num+5],2,2)
//SetSpriteColor(radarSprites[num+5],0,200,0,255)
//SetSpriteDepth(radarSprites[num+5],0)
next num
//radar=2
playerShip.id=1:playerShip.velocity=0
createSprite(playerShip.id,1)
SetSpriteOffset(playerShip.id,64,64)
SetSpritePositionByOffset(playerShip.id,512,384)
setSpriteSize(playerShip.id,64,96)
SetSpriteDepth(playerShip.id,0)
//CreateSprite(radar,radar)
//SetSpritePositionByOffset(radar,GetVirtualWidth()-GetImageWidth(radar),GetVirtualHeight()-GetImageHeight(radar))
//SetSpriteOffSet(radar,1,1)
//SetSpriteDepth(radar,1)
//radarSprites[16]=CreateSprite(0)
//SetSpriteSize(radarSprites[16],2,2)
//SetSpriteColor(radarSprites[16],0,150,0,255)
//SetSpriteDepth(radarSprites[16],0)
LoadSound( 70, "bigexplosion.wav" )
for num=1 to 10
//Front shooting bullets
LoadSound( num+50, "smallexplosion.wav" )
playerBullets[num,1].id=num+50
createSprite(playerBullets[num,1].id,0)
playerBullets[num,1].x=512
playerBullets[num,1].y=384
playerBullets[num,1].angle=0
playerBullets[num,1].count=(num-1)*40
SetSpritePositionByOffset(playerBullets[num,1].id,playerBullets[num,1].x,playerBullets[num,1].y)
setSpriteSize(playerBullets[num,1].id,4,4)
SetSpriteDepth(playerBullets[num,1].id,1)
setSpriteColor(playerBullets[num,1].id,255,255,255,255)
//Rear shooting bullets
LoadSound( num+60, "smallexplosion.wav" )
playerBullets[num,2].id=num+60
createSprite(playerBullets[num,2].id,0)
playerBullets[num,2].x=512
playerBullets[num,2].y=384
playerBullets[num,2].angle=0
playerBullets[num,2].count=(num-1)*40
SetSpritePositionByOffset(playerBullets[num,2].id,playerBullets[num,2].x,playerBullets[num,2].y)
setSpriteSize(playerBullets[num,2].id,4,4)
SetSpriteDepth(playerBullets[num,2].id,1)
setSpriteColor(playerBullets[num,2].id,255,255,255,255)
next num
endfunction
function scrollSprites()
x# = GetPointerX()
y# = GetPointerY()
a#=getAngle(x#,y#,GetVirtualWidth()/2,GetVirtualHeight()/2)
SetSpriteAngle(playerShip.id,a#)
spd#=getDistance(x#,y#,GetSpriteXByOffset(playerShip.id),GetSpriteYByOffset(playerShip.id))
//calculate and store a velocity factor
if playerShip.velocity<spd#
playerShip.velocity=playerShip.velocity+10
endif
if playerShip.velocity>spd#
playerShip.velocity=playerShip.velocity-10
endif
if playerShip.velocity<0 then playerShip.velocity=0
if playerShip.velocity>540 then playerShip.velocity=540
amount#=7
//players bullets num,1 forward num.2 backward
for t = 1 to 2
for num=1 to 10
if playerBullets[num,t].count=1
SetSpriteAngle(playerBullets[num,t].id,a#)
playerBullets[num,t].angle=a#
//bullets[num].count=1
endif
if playerBullets[num,t].count>1 //and playerBullets[num].spawn=1
playerBullets[num,t].x=playerBullets[num,t].x+sin(playerBullets[num,t].angle)*amount#
playerBullets[num,t].y=playerBullets[num,t].y-cos(playerBullets[num,t].angle)*amount#
setSpritePosition(playerBullets[num,t].id,playerBullets[num,t].x,playerBullets[num,t].y)
endif
if playerBullets[num,t].count>400
playerBullets[num,t].angle=0
playerBullets[num,t].count=0
playerBullets[num,t].x=512
playerBullets[num,t].y=384
if GetSpritePlaying(playerBullets[num,t].id)=0
SetSpriteSize(playerBullets[num,t].id,4,4)
SetSpriteImage(playerBullets[num,t].id,0)
SetSpriteOffset(playerBullets[num,t].id,2,2)
SetSpriteColor(playerBullets[num,t].id,255,255,255,255)
endif
endif
playerBullets[num,t].count=playerBullets[num,t].count+1
checkPlayerBullet(playerBullets[num,t].id)
next num
amount#=-7
next t
//Enemy fighter bullets
amount#=5
for num = 1 to 10
//amount2#=2 //enemy fighter bullets
for num2=1 to 5
if enemyFighter[num].enemybullets[num2].count=1
enemyFighter[num].enemybullets[num2].angle=enemyFighter[num].angle
enemyFighter[num].enemybullets[num2].x=enemyFighter[num].x
enemyFighter[num].enemybullets[num2].y=enemyFighter[num].y
SetSpriteAngle(enemyFighter[num].enemybullets[num2].id,enemyFighter[num].enemybullets[num2].angle)
SetSpritePositionByOffset(enemyFighter[num].enemybullets[num2].id,enemyFighter[num].enemybullets[num2].x,enemyFighter[num].enemybullets[num2].y)
//enemyFighter[num].enemybullets[num2].count=1
endif
if enemyFighter[num].enemybullets[num2].count>1 //and playerBullets[num].spawn=1
enemyFighter[num].enemybullets[num2].x=enemyFighter[num].enemybullets[num2].x+(sin(enemyFighter[num].enemybullets[num2].angle)*amount#)
enemyFighter[num].enemybullets[num2].y=enemyFighter[num].enemybullets[num2].y-(cos(enemyFighter[num].enemybullets[num2].angle)*amount#)
SetSpritePositionByOffset(enemyFighter[num].enemybullets[num2].id,enemyFighter[num].enemybullets[num2].x,enemyFighter[num].enemybullets[num2].y)
endif
if enemyFighter[num].enemybullets[num2].count>100
enemyFighter[num].enemybullets[num2].angle=0
enemyFighter[num].enemybullets[num2].count=0
enemyFighter[num].enemybullets[num2].x=enemyFighter[num].x
enemyFighter[num].enemybullets[num2].y=enemyFighter[num].y
//if GetSpritePlaying(enemyFighter[num].enemybullets[num2].id)=0
SetSpriteSize(enemyFighter[num].enemybullets[num2].id,4,4)
SetSpriteImage(enemyFighter[num].enemybullets[num2].id,0)
SetSpriteOffset(enemyFighter[num].enemybullets[num2].id,2,2)
SetSpriteColor(enemyFighter[num].enemybullets[num2].id,255,255,255,255)
//endif
endif
enemyFighter[num].enemybullets[num2].count=enemyFighter[num].enemybullets[num2].count+1
if checkEnemyBullet(enemyFighter[num].enemyBullets[num2].id)=1
SetSpriteVisible(playerShip.id,0)
while GetSpritePlaying(enemyFighter[num].enemybullets[num2].id)
sync()
endwhile
resetShips()
SetSpriteVisible(playerShip.id,1)
exitfunction
endif
next num2
next num
amount#=playerShip.velocity/60
for y = 1 to 10
for x = 1 to 10
x# = getSpriteX(stars[x,y])
y# = GetSpriteY(stars[x,y])
setSpritePosition(stars[x,y],x#-sin(a#)*amount#,y#+cos(a#)*amount#)
if getSpriteY(stars[x,y])<0
setSpritePosition (stars[x,y], getSpritex(stars[x,y]), GetSpriteY (stars[x,y]) + GetVirtualHeight())
endif
if getSpriteY(stars[x,y]) > GetVirtualHeight()
setSpritePosition (stars[x,y], getSpriteX(stars[x,y]), GetSpriteY (stars[x,y]) -GetVirtualHeight())
endif
if getSpriteX(stars[x,y])<0
setSpritePosition (stars[x,y], GetSpriteX (stars[x,y]) + GetVirtualWidth(), GetSpriteY (stars[x,y]))
endif
if getSpriteX(stars[x,y])> getVirtualWidth()
setSpritePosition (stars[x,y], GetSpriteX (stars[x,y]) - GetVirtualWidth(), GetSpriteY (stars[x,y]))
endif
next x
next y
//amount#=10
amount#=playerShip.velocity/40
//print (amount#)
for num=1 to 5
x# = GetSpriteXByOffset(spaceStations[num].id)
y# = GetSpriteYByOffset(spaceStations[num].id)
SetSpritePositionByOffset(spaceStations[num].id,x#-sin(a#)*amount#,y#+cos(a#)*amount#)
if GetSpriteYByOffset(spaceStations[num].id)<-256
SetSpritePositionByOffset (spaceStations[num].id, GetSpriteXByOffset(spaceStations[num].id), GetSpriteYByOffset (spaceStations[num].id) + mapHeight)
endif
if GetSpriteYByOffset(spaceStations[num].id) >GetVirtualHeight()+256
SetSpritePositionByOffset (spaceStations[num].id, GetSpriteXByOffset(spaceStations[num].id),GetSpriteYByOffset (spaceStations[num].id)-mapHeight )
endif
if GetSpriteXByOffset(spaceStations[num].id)<-256
SetSpritePositionByOffset (spaceStations[num].id, GetSpriteXByOffset (spaceStations[num].id) + mapWidth, GetSpriteYByOffset (spaceStations[num].id))
endif
if GetSpriteXByOffset(spaceStations[num].id)> getVirtualWidth()+256
SetSpritePositionByOffset (spaceStations[num].id, GetSpriteXByOffset (spaceStations[num].id)-mapWidth, GetSpriteYByOffset (spaceStations[num].id))
endif
next num
//move away from enemy fighters and bullets (in effect it moves ship which really is stationary in centre of screen)
for num = 1 to 10
x# = GetSpriteXByOffset(enemyFighter[num].id)
y# = GetSpriteYByOffset(enemyFighter[num].id)
enemyFighter[num].x=x#-sin(a#)*amount#
enemyFighter[num].y=y#+cos(a#)*amount#
SetSpritePositionByOffset(enemyFighter[num].id,enemyFighter[num].x,enemyFighter[num].y)
for num2 = 1 to 5
x# = GetSpriteXByOffset(enemyFighter[num].enemyBullets[num2].id)
y# = GetSpriteYByOffset(enemyFighter[num].enemyBullets[num2].id)
enemyFighter[num].enemyBullets[num2].x=x#-sin(a#)*amount#
enemyFighter[num].enemyBullets[num2].y=y#+cos(a#)*amount#
SetSpritePositionByOffset(enemyFighter[num].enemyBullets[num2].id,enemyFighter[num].enemyBullets[num2].x,enemyFighter[num].enemyBullets[num2].y)
next num2
next num
//move enemy with velocity
for num = 1 to 10
spd#=getDistance(x#,y#,GetSpriteXByOffset(playerShip.id),GetSpriteYByOffset(playerShip.id))
if enemyFighter[num].velocity<spd#
enemyFighter[num].velocity=enemyFighter[num].velocity+10
endif
if enemyFighter[num].velocity>spd#
enemyFighter[num].velocity=enemyFighter[num].velocity-10
endif
if enemyFighter[num].velocity<0 then enemyFighter[num].velocity=0
if enemyFighter[num].velocity>500 then enemyFighter[num].velocity=500
amount#=enemyFighter[num].velocity/60
//amount#=1
a#=getAngle(GetSpriteXByOffset(playerShip.id),GetSpriteYByOffset(playerShip.id),GetSpriteXByOffset(enemyFighter[num].id),GetSpriteYByOffset(enemyFighter[num].id))
enemyFighter[num].angle=a#
SetSpriteAngle(enemyFighter[num].id,enemyFighter[num].angle)
if enemyFighter[num].count>=100 and getDistance(enemyFighter[num].x,enemyFighter[num].y,GetSpriteXByOffset(playerShip.id),GetSpriteYByOffset(playerShip.id))>=300
enemyFighter[num].x=enemyFighter[num].x+sin(enemyFighter[num].angle)*amount#
enemyFighter[num].y=enemyFighter[num].y-cos(enemyFighter[num].angle)*amount#
SetSpritePositionByOffset(enemyFighter[num].id,enemyFighter[num].x,enemyFighter[num].y)
endif
if enemyFighter[num].count>1000
enemyFighter[num].angle=0
enemyFighter[num].count=0
enemyFighter[num].velocity=0
enemyFighter[num].x=GetSpriteXByOffset(spaceStations[3].id)
enemyFighter[num].y=GetSpriteYByOffset(spaceStations[3].id)
SetSpritePositionByOffset(enemyFighter[num].id,enemyFighter[num].x,enemyFighter[num].y)
endif
enemyFighter[num].count=enemyFighter[num].count+1
next num
endfunction
function checkPlayerBullet(playerBullet as integer)
for num=1 to 10
if GetSpriteCollision(playerBullet,enemyFighter[num].id) and GetSpritePlaying(playerBullet)=0
SetSpriteImage(playerBullet,explosionImage)
SetSpriteAnimation(playerBullet,256,256,25)
SetSpriteSize(playerBullet,128,128)
SetSpriteOffset(playerBullet,64,64)
SetSpritePositionByOffset(playerBullet,enemyFighter[num].x,enemyFighter[num].y)
PlaySound(playerBullet)
playSprite(playerBullet,10,0)
//render()
enemyFighter[num].x=GetSpriteXByOffset(spaceStations[3].id)
enemyFighter[num].y=GetSpriteYByOffset(spaceStations[3].id)
SetSpritePositionByOffset(enemyFighter[num].id,enemyFighter[num].x,enemyFighter[num].y)
playerShip.score=playerShip.score+50
endif
next num
for num= 1 to 5
if GetSpriteCollision(playerBullet,spaceStations[num].id) and GetSpritePlaying(playerBullet)=0 and spaceStations[num].gone=0
tempX=GetSpriteWidth(spaceStations[num].id)
tempY=GetSpriteHeight(spaceStations[num].id)
SetSpriteImage(playerBullet,explosionImage)
SetSpriteAnimation(playerBullet,256,256,25)
SetSpriteSize(playerBullet,128,128)
SetSpriteOffset(playerBullet,64,64)
SetSpritePositionByOffset(playerBullet,spaceStations[num].x,spaceStations[num].y)
PlaySound(playerBullet)
playSprite(playerBullet,10,0)
playerScore=playerScore+10
//render()
spaceStations[num].hitpoints=spaceStations[num].hitpoints-1
if spaceStations[num].hitpoints<1 and spaceStations[num].gone=0
tempX=GetSpriteWidth(spaceStations[num].id)
tempY=GetSpriteHeight(spaceStations[num].id)
SetSpriteImage(spaceStations[num].id,explosionImage)
SetSpriteAnimation(spaceStations[num].id,256,256,25)
SetSpriteSize(spaceStations[num].id,tempX,tempY)
SetSpriteOffset(spaceStations[num].id,tempX/2,tempY/2)
SetSpritePositionByOffset(playerBullet,spaceStations[num].x,spaceStations[num].y)
PlaySound(70)
playSprite(spaceStations[num].id,10,0)
spaceStations[num].gone=1:dec spaceStationCounter
playerShip.score=playerShip.score+(1000*level)
endif
endif
next num
endfunction
function checkEnemyBullet(enemyBullet as integer)
flag =0
if GetSpriteCollision(enemyBullet,playerShip.id) and GetSpritePlaying(enemyBullet)=0
SetSpriteImage(enemyBullet,explosionImage)
SetSpriteAnimation(enemyBullet,256,256,25)
SetSpriteSize(enemyBullet,128,128)
SetSpriteOffset(enemyBullet,64,64)
SetSpriteDepth(enemyBullet,0)
SetSpritePositionByOffset(enemyBullet,GetSpriteXByOffset(playerShip.id),GetSpriteYByOffset(playerShip.id))
playSprite(enemyBullet,10,0)
playerShip.lives=playerShip.lives-1
if playerShip.lives < 0 then playerShip.lives=0
flag=1
endif
endfunction flag
function displayScore()
if GetTextExists(700)=0
CreateText(700,"Score:"+str(playerShip.score))
else
SetTextString(700,"Score:"+str(playerShip.score))
endif
SetTextPosition(700,0,0)
SetTextSize(700,35)
SetTextColor(700,255,255,255,255)
if GetTextExists(701)=0
CreateText(701,"Lives:"+str(playerShip.lives))
else
SetTextString(701,"Lives:"+str(playerShip.lives))
endif
SetTextPosition(701,0,35)
SetTextSize(701,35)
SetTextColor(701,255,255,255,255)
if highscore<playerShip.score then highscore=playerShip.score
if GetTextExists(702)=0
CreateText(702,"High:"+str(highscore))
else
SetTextString(702,"High:"+str(highscore))
endif
SetTextPosition(702,GetVirtualWidth()-240,0)
SetTextSize(702,35)
SetTextColor(702,255,255,255,255)
endfunction
function loadMap(filename$ as string)
if GetFileExists( filename$ ) =0
message("file "+filename$+" not found")
end
exitfunction "error"
endif
file = OpenToRead(filename$)
//both must be powers of the screen size
mapWidth=val(readline(file))
mapHeight=val(readline(file))
levelColor$=readline(file)
for num=1 to 5
spaceStations[num].id=num+99
spaceStations[num].gone=0
spaceStations[num].x=val(readline(file))
spaceStations[num].y=val(readline(file))
spaceStations[num].image=val(readline(file))
spaceStations[num].hitpoints=val(readline(file))
next num
CloseFile ( file )
//Print (toInt (maxJokes))
endfunction levelColor$
function resetShips() //used after player loses a life the ships need to be reset
for num = 1 to 5
SetSpritePositionByOffset(spaceStations[num].id,spaceStations[num].x,spaceStations[num].y)
next num
temp=300
for num = 1 to 10
enemyFighter[num].count=(num-1)*100
enemyFighter[num].velocity=0
enemyFighter[num].x=GetSpriteXByOffset(spaceStations[3].id):rem+224
enemyFighter[num].y=GetSpriteYByOffset(spaceStations[3].id):rem+192
SetSpritePositionByOffset(enemyFighter[num].id,enemyFighter[num].x,enemyFighter[num].y)
SetSpriteDepth(enemyFighter[num].id,2)
for bullets=1 to 5
//Front shooting enemy bullets
enemyFighter[num].enemybullets[bullets].id=temp
createSprite(enemyFighter[num].enemybullets[bullets].id,0)
enemyFighter[num].enemybullets[bullets].x=0
enemyFighter[num].enemybullets[bullets].y=0
enemyFighter[num].enemybullets[bullets].angle=0
enemyFighter[num].enemybullets[bullets].count=(num-1)*20
SetSpritePositionByOffset(enemyFighter[num].enemybullets[bullets].id,enemyFighter[num].enemybullets[bullets].x,enemyFighter[num].enemybullets[bullets].y)
inc temp
next bullets
next num
endfunction
function getAngle(x1#, y1#, x2#, y2#)
result# = ATanFull(x1# - x2#, y1# - y2#)
endfunction result#
function getDistance (x1#,y1#,x2#,y2#)
dx#=x1#-x2#
dy#=y1#-y2#
distance#=sqrt((dx#*dx#)+(dy#*dy#)):rem distance from the pointer to the ship
endfunction distance#
function gameover()
//playSound(70)
a=GetVirtualHeight()
dim i[100]
dim s[100]
//sync()
spr=loadsprite("gameover.png") //<- any background image
setspritesize(spr,500,100)
SetSpritePosition(spr,(getvirtualwidth()-500)/2,(getvirtualheight()-100)/2)
ClearScreen()
drawsprite(spr)
Render()
MakeWave()
deletesprite(spr)
sync()
w#=0
w#=0
time#=timer()
while (timer()-time#)<3.0
DoWave(w#)
w#=w#+360.0/20.0
if w#>360.0 then w#=w#-360.0
if getpointerpressed()=1 then exit
Sync()
endwhile
FreeWave()
endfunction
function advanceLevel(levelColor$ as string)
//playSound(70)
a=GetVirtualHeight()
dim i[100]
dim s[100]
//sync()
spr=loadsprite(levelColor$+"level.png")
setspritesize(spr,500,100)
SetSpritePosition(spr,(getvirtualwidth()-500)/2,(getvirtualheight()-100)/2)
ClearScreen()
drawsprite(spr)
Render()
MakeWave()
deletesprite(spr)
sync()
w#=0
time#=timer()
while (timer()-time#)<3.0
DoWave(w#)
w#=w#+360.0/20.0
if w#>360.0 then w#=w#-360.0
Sync()
endwhile
FreeWave()
endfunction
// the wave effect is used at end of game
function MakeWave()
vw=getvirtualwidth()
vh=getvirtualheight()
for y=0 to 99
//Render()
i[y]=GetImage( (vw-500)/2,((vh-100)/2)+y,vw, 1.0 )
//s[y]=createsprite(i[y])
s[y]=1000+y
createsprite(s[y],i[y])
setspritesize(s[y],vw,1.5)
setspriteposition(s[y],(vw-500)/2,y)
setspritedepth(s[y],0)
next
endfunction
function DoWave(w#)
vw=getvirtualwidth()
vh=getvirtualheight()
for y=0 to 99
setspriteposition(s[y],cos(w#)+((vw-500)/2),(y+((vh-100)/2))+sin(w#)*1.0)
w#=w#+360.0/100.0
next
endfunction
function FreeWave()
for y=0 to 99
deletesprite(s[y])
s[y]=0
deleteimage(i[y])
i[y]=0
next
endfunction
the last bit just fixes the level wave and end of game graphics under windows no idea why it doesn't show on all android phones or under html but works fine under windows
stops the brief flash of the wave appearing at top of screen prior to its movement changes which was source I got out of the forums so I don't deserve credit for that
fubar