Hello.
I am writing a program for a top down 2D space shooter. I have figured out most of the basics of the game, I can move my ship and shoot a laser which will destroy enemy ships on screen. This will delete the enemy sprite and add points to the player's score.
The problem is that I can't get the enemy ships to mvoe by themselves on a set path across the screen. At the moment, all they do is stay in the same place. I can get them to move in one direction only, but even then they don't disappear when shot since the image is still getting loaded in.
I also need help getting the enemy ships to shoot their own laser at random times, but I have no idea how to implement this.
Here is my code at the moment:
sync rate 60
sync on
set display mode 1280,1024,32
ink rgb (255,255,255),0
set text size 50
set text font "Digital SF"
gosub variables
variables:
load image "images\space.jpg",1
load image "images\player ship.jpg",2
load image "images\laser.jpg",3
load image "images\enemyship1.jpg",4
load image "images\enemy ship2.jpg",5
load image "images\enemyship3.jpg",6
playerx = 640
playery = 950
en1x = 500
en1y = 500
en2x = 350
en2y = 400
en3x = 600
en3y = 700
score = 0
lives = 3
gosub load_enemies
gosub player_and_enemy_movement
load_enemies:
sprite 4,en1x,en1y,4
sprite 5,en2x,en2y,5
sprite 6,en3x,en3y,6
return
player_and_enemy_movement:
Do
paste image 1,0,0
If leftkey()=1 and playerx =>0 then playerx = playerx - 5
If rightkey()=1 and playerx <=1230 then playerx = playerx + 5
sprite 2,playerx,playery,2
if spacekey()=1 and bulletfired = 0
bulletfired = 1
bulletx = playerx + 15
bullety = playery + 5
endif
if bulletfired = 1
gosub bulletmove
gosub collision
endif
text 0,0,"Score:"
text 120,0,str$(score)
text 900,0,"Lives:"
text 1020,0,str$(lives)
Sync
loop
bulletmove:
sprite 3,bulletx,bullety,3
bullety = bullety - 10
if bullety = 0
dec bullety,5
sprite 3,bulletx,bullety,3
endif
if bullety <=0
sprite 3,2000,2000,3
bulletfired = 0
endif
return
collision:
if sprite hit (3,4)
delete sprite 4
sprite 3,2000,2000,3
score = score + 100
bulletfired = 0
endif
if sprite hit (3,5)
delete sprite 5
sprite 3,2000,2000,3
score = score + 100
bulletfired = 0
endif
if sprite hit (3,6)
delete sprite 6
sprite 3,2000,2000,3
score = score + 100
bulletfired = 0
endif
return
So to sum up, how can I get the enemy ship sprites to move both ways in the X axis on it's own accord and to disappear when it comes into contact with the player laser? Also, how do I implement enemy sprites shooting lasers at random or specific times?
Thanks for all help in advance guys.