You're welcome. I made some more changes to help it run better and look a little cleaner:
set display mode 1024, 600, 32
sync on : sync rate 60
backdrop off : hide mouse
randomize timer()
set text font "Bookman Old Style"
global health : health = 100
global speed : speed = 0
global angle : angle = 0
global score : score = 0
global GameOver : GameOver = 0
global TimeToGo : TimeToGo = 0
global numberofenemies : NumberOfEnemies = 0
global MaxEnemies : MaxEnemies = 5
global MissileSpeed : MissileSpeed = 3
global ScreenWidth : ScreenWidth = screen width()
global ScreenHeight : ScreenHeight = screen height()
global MaxRight : global MaxDown
global MissileDelay : global EnemyAppear
load image "ship.png", 1
load image "bullet.png", 2
load image "enemy.png", 3
dim missile(3) : dim enemy(5,3)
MainMenu()
sprite 1, 500, 300, 1 : ` ship
offset sprite 1,sprite width(1) / 2,sprite height(1) / 2
MaxRight = ScreenWidth - sprite width(1) : ` pre-calculate the right side of the screen for the player
MaxDown = ScreenHeight - sprite height(1) : ` pre-calculate the bottom of the screen for the player
MissileDelay = timer() + 150 : EnemyAppear = timer() + 1500 : ` have a new enemy appear every 1.5 seconds
repeat
cls
ink rgb(255,255,0),0
text 0,0,"Health:"
box 0, 15, health, 25
UserInput()
` check to see if we have any active missiles
ActiveMissile = 0
for m = 1 to 3
if missile(m) > 0 then ActiveMissile = 1
next m
if ActiveMissile = 1 then MoveMissiles() : `yes, move them
if numberofenemies < MaxEnemies then newenemy()
MoveEnemies()
sync
if GameOver > 0 then GameIsOver() : MainMenu()
until TimeToGo = 1
end
function UserInput()
OldX = sprite x(1) : OldY = sprite y(1)
if upkey() = 1
speed = 2
else
speed = 0
endif
if rightkey() = 1 then angle = angle + 2
if leftkey() = 1 then angle = angle - 2
if returnkey() = 1 then sprite 1, 300, 300, 1
rotate sprite 1, angle
move sprite 1, speed
NewX = sprite x(1) : NewY = sprite y(1)
if NewX < 0 or NewX > MaxRight then NewX = OldX : ` make sure the player does not go off the screen
if NewY < 0 or NewY > MaxDown then NewY = OldY : ` ditto
sprite 1,NewX,NewY,1 : ` re-draw the player sprite at our adjusted coordinates
if spacekey() = 1 and timer() > MissileDelay
` first, check to see if a missile is available
avbl = 0
for m = 1 to 3
if missile(m) = 0 then avbl = m
next m
if avbl > 0 : ` yep, create one at the ship's location
missile(avbl) = 1
sprite (9 + avbl), sprite x (1) , sprite y(1), 2 : ` use 10 - 12 sprites for missiles
offset sprite 9 + avbl,sprite width(9 + avbl) / 2,sprite height(9 + avbl) / 2
rotate sprite (9 + avbl), sprite angle(1)
move sprite 9 + avbl,25 : ` move it out near the nosecone
MissileDelay = timer() + 750 : ` wait 3/4 of one second before the user can fire another missile
endif
endif
endfunction
function MainMenu()
c = 0
repeat
cls
set text size 72 : set text to italic
box 100,10,ScreenWidth - 100,150,rgb(255,0,0),rgb(0,255,0),rgb(0,0,255),255
ink rgb(255,255,255),0
center text ScreenWidth / 2,50,"Main Menu"
set text to normal : set text size 28
ink rgb(255,255,0),0
text 150,220,"1. Play Game"
text 150,250,"2. Controls (not active)"
text 150,280,"3. Difficulty (not active)"
text 150,310,"4. Sound/Music (not active)"
text 150,340,"5. Quit"
ink rgb(255,0,255),0
text 150,400,"Your choice?"
c = scancode()
if c >= 3 and c <= 6
select c
case 3
` Contols()
endcase
case 4
` Difficulty()
endcase
case 5
` SoundAndMusic()
endcase
case 6 : ` quit
DeleteAllSprites() : end
endcase
endselect
endif
sync
until c = 2
set text size 16
endfunction
function MoveEnemies()
for e = 1 to MaxEnemies
if enemy(e,1) > 0
move sprite 49 + e,enemy(e,2)
` check to see if it is off screen
if sprite x(49 + e) < 0 or sprite x(49 + e) > ScreenWidth or sprite y(49 + e) < 0 or sprite y(49 + e) > ScreenHeight
delete sprite 49 + e : enemy(e,1) = 0 : dec numberofenemies
newenemy() : ` off screen -- replace it with another enemy
endif
` check to see if it collided with the player's ship
if sprite collision(1,49 + e) = 1
` enemy has collided with player
dec health,20
if health < 0 then health = 0 : GameOver = 1
` delete enemy -- normally, you would place an explosion where the enemy was
if sprite exist(49 + e) = 1 then delete sprite 49 + e
enemy(e,1) = 0
newenemy()
endif
endif
next e
endfunction
function newenemy()
baddie = 0
for e = 1 to MaxEnemies
if Enemy(e,1) = 0 and baddie = 0 then baddie = e : Enemy(e,1) = 1 : ` enemy status = active
next e
if baddie = 0 then exitfunction
if sprite exist(49 + baddie) = 1 then delete sprite 49 + baddie :` if enemy sprite exists already, get rid of it
sprite 49 + baddie,rnd(900),-rnd(100),3 : ` create the enemy sprite
rotate sprite 49 + baddie,180 : ` rotate it so that it faces down
enemy(baddie,2) = rnd(1) + 1 : ` vary the speed slightly for the enemies
inc numberofenemies
ENDFUNCTION
function MoveMissiles()
for m = 1 to 3
if missile(m) > 0
move sprite (9 + m),MissileSpeed
` check collision with enemies
for e = 1 to MaxEnemies
if enemy(e,1) > 0 and missile(m) > 0
if sprite collision(9 + m,e + 49) = 1
` got em!!
inc score, 100
delete sprite e + 49
enemy(e,1) = 0
dec numberofenemies
` delete the player's missile
delete sprite 9 + m
missile(m) = 0
newenemy() : ` create a new enemy
endif
endif
next e
`if still active, check if off screen
if missile(m) > 0
if sprite x(9 + m) < 0 or sprite x(9 + m) > ScreenWidth or sprite y(9 + m) < 0 or sprite y(9 + m) > ScreenHeight
delete sprite 9 + m
missile(m) = 0
endif
endif
endif
next m
endfunction
function DeleteAllSprites()
if sprite exist(1) = 1 then delete sprite 1 : ` player
for m = 1 to 3
if missile(m) > 0
if sprite exist(9 + m) = 1 then delete sprite 9 + m : ` missiles
endif
next m
for e = 1 to MaxEnemies
if Enemy(e,1) = 1
if sprite exist(49 + e) = 1 then delete sprite 49 + e : ` enemies
endif
next e
endfunction
function GameIsOver()
set text size 72
DeleteAllSprites()
ink rgb(255,0,0),0
center text ScreenWidth / 2,ScreenHeight / 2,"Game Over"
sync
set text size 20
ink rgb(0,255,255),0
wait 5
center text ScreenWidth / 2, (ScreenHeight / 2) + 100,"Thanks for playing."
sync
wait 2500
endfunction
Computers do exactly what you tell them.........don't you hate that sometimes?