hi Jonty
This post has been edited please re-read it
I Figured out the problem of the laser not reappearing, you were not resetting the firepress variable, also I've changed a few things, I've marked in the code where they are
REM *********************************************************************
REM Name: Lunar Wars *
REM Author: Phil Goodier *
REM Description: Scrolling shoot em up game set in space. Enemies set *
REM up in formation and move towards the player's ship *
REM and destroy it if they collide. The player has to *
REM fire lasers at the enemy to destroy them. The level *
REM ends when all of the enemies are destroyed. *
REM *********************************************************************
sync on
sync rate 30
color backdrop 0
hide mouse
REM Load images for ships, background and lasers
load image "playership.bmp",1
load image "enemyship1.bmp",2
load image "enemyship2.bmp",3
load image "enemyship3.bmp",4
load image "laser.bmp",5
load image "stars.bmp",6
load image "exp1.bmp",7
load image "exp2.bmp",8
load image "exp3.bmp",9
load image "exp4.bmp",10
load image "exp5.bmp",11
load image "exp6.bmp",12
load image "logo.bmp",25
load image "titlescreen.bmp",100
load image "victory.bmp",999
REM Load all of the sounds and music for the game
load music "theme.mid",1
load sound "laser.wav",2
load sound "explosion.wav",3
load music "victory.mid",4
REM Title screen
play music 1
sprite 100,0,0,100
wait key
delete sprite 100
REM Create object and put the stars as a texture
make object plain 4,125,56
position object 4,0,0,80
texture object 4,6
lock object on 4
color backdrop rgb(0,0,0)
REM Variables for SCORE, NUMBER OF LIVES and LEVEL
score=0:level=1:lives=3
REM Set coordinates for player ship
psx=50:psy=225
REM This variable stores 1 when a laser has been fired by the player and will be used to limit the lasers on screen to 1
firepress=0
REM Put the ship sprite onto the screen
sprite 1,psx,psy,1
REM Position logo onto the screen
sprite 25,268,24,25
REM This draws the enemy ship
gosub shipFormation1
do
REM Print the SCORE, NUMBER OF LIVES and the LEVEL to the screen
set cursor 130,400: print "SCORE: ";score;" LEVEL: ";level;" LIVES: ";lives;" ENEMIES LEFT: ";enemynumber
REM Move the player's ship up
if UPKEY()=1 and psy>100
dec psy,10
endif
REM Move the player's ship down
if DOWNKEY()=1 and psy<370
inc psy,10
endif
REM Fire a laser
if SPACEKEY()=1 and firepress=0
gosub laserFire
firepress=1
endif
REM This section of code determines if an enemy ship has been hit by a laser
if SPRITE EXIST(2)=1
spritemax=maxsprite
for spriteno=10 to maxsprite
if SPRITE HIT(2,spriteno)=1
deadx = SPRITE X(spriteno)
deady = SPRITE Y(spriteno)
gosub explosion
score=score+10
`*******************************************************************************
`Added these
`You forgot to reset firepress to 0 which is why the laser didn't come back
firepress = 0
`This exits the for loop, because if you delete sprite 2 in the explosion
`subroutine, unless spriteno = maxsprite you'll get a run-time error because
`sprite 2 does not exist and your trying to check its collision
exit
`*******************************************************************************
endif
next spriteno
endif
REM Redraw ship sprite
sprite 1,psx,psy,1
REM Call the background scrolling function and the laser moving function
gosub moveBackground
gosub moveAll
if level=1 and enemynumber=0
gosub shipFormation2
else
if level=2 and enemynumber=0
gosub shipFormation3
else
if level=3 and enemynumber=0
gosub victory
endif
endif
endif
sync
loop
REM Function to make the background move
moveBackground:
scroll object texture 4,0.05,0.0
return
REM Function to make the lasers move forwards
moveAll:
if SPRITE EXIST(2)=1
if sprite X(2)<640
laserx=laserx+45
sprite 2,laserx,lasery,5
endif
if sprite X(2)>640
firepress=0
delete sprite 2
laserx=SPRITE X(1)+20
lasery=SPRITE Y(1)+7
endif
endif
return
REM Function that fires a laser
laserFire:
`****************************************************************************************
`Added this
REM These are the coordinates of the laser so that they are fired from the front of the ship
laserx=SPRITE X(1)+20
lasery=SPRITE Y(1)+8
`****************************************************************************************
sprite 2,laserx,lasery,5
play sound 2
return
REM Function that places the ships for level 1
shipFormation1:
enemynumber=15
level = 1
REM Back row
enemyx=575:enemyy=100
for spriteno=10 to 15
sprite spriteno,enemyx,enemyy,2
enemyy=enemyy+50
next spriteno
REM Middle row
enemyx=475:enemyy=120
for spriteno=16 to 20
sprite spriteno,enemyx,enemyy,2
enemyy=enemyy+50
next spriteno
REM Front row
enemyx=375:enemyy=140
for spriteno=21 to 24
sprite spriteno,enemyx,enemyy,2
enemyy=enemyy+50
next spriteno
maxsprite=spriteno
return
REM Function that places the ships for level 2
shipFormation2:
enemynumber=15
level = 2
REM Back row
enemyx=575:enemyy=100
for spriteno=10 to 14
sprite spriteno,enemyx,enemyy,3
enemyy=enemyy+62
next spriteno
REM Middle Row
enemyx=475:enemyy=200
for spriteno=15 to 17
sprite spriteno,enemyx,enemyy,3
enemyy=enemyy+30
next spriteno
REM Front Row
enemyx=375:enemyy=140
for spriteno=18 to 24
sprite spriteno,enemyx,enemyy,3
enemyy=enemyy+30
next spriteno
maxsprite=spriteno
return
REM Function that places the ships for level 3
shipFormation3:
enemynumber=15
level = 3
REM Back row
enemyx=575:enemyy=100
for spriteno=10 to 17
sprite spriteno,enemyx,enemyy,4
enemyy=enemyy+40
next spriteno
REM Middle Row
enemyx=475:enemyy=180
for spriteno=18 to 20
sprite spriteno,enemyx,enemyy,4
enemyy=enemyy+50
next spriteno
REM Front Row
enemyx=375:enemyy=140
for spriteno=21 to 24
sprite spriteno,enemyx,enemyy,4
enemyy=enemyy+60
next spriteno
maxsprite=spriteno
return
REM This function creates the explosion animation for when an enemy ship is hit
explosion:
delete sprite 2
play sound 3
for explosionframe = 7 to 12
sprite spriteno,deadx,deady,explosionframe
sync
delete sprite spriteno
next explosionframe
enemynumber=enemynumber-1
return
REM This function brings up the victory screen for when the player wins the game
victory:
stop music 1
sprite 999,0,0,999
play music 4
wait key
end
return
enjoy
pizzaman