@Daygamer
control_player:
`# cls
`# rem decide which subroutine to head to for drawing objects
`# if sprites_on = 1 then gosub load_sprites : gosub draw_sprites
`# if sprites_on = 0 then gosub without_sprites
rem controls for moving player side to side
rem it will not let the player move out of the screen
if playerx < 600 and rightkey()=1 then inc playerx, 2
if playerx > 40 and leftkey()=1 then dec playerx, 2
return
I've marked the lines for deletion with #.
We don't want a cls in there because that's a display command and should be only in the display sub.
I see what you're doing with the sprites_on flag but if there are no images ready simple images will be generated as placeholders and used in sprites so the program will be the same.
You need to add in this sub the firing bullets code. It should check if there is a player bullet in existence (only one at a time) and if there's no bullet and the player presses spacebar fire a bullet. All you need to fire a bullet is to set the bullet xy to the gun position (there is a slight problem with this, can you see it?) and make a flag called player_bullet or something that is 1 when a player bullet exists.
Use that switch I showed you so the player can't hold down space for continuous firing.
Ah, I see you have put the code in the update_bullet sub, that's the wrong place; update_bullet is a processing sub, it's a number cruncher, all input commands should be in the input sub control_player.
I see you've thought of continuous firing, and the problem with positioning the bullet on the player (it would count as a hit on the player).
Your fire_lock is not as neat as the switch I showed earlier.
Just a small tip before I add that, when you check a variable in a condition and inside the condition that variable is changed it is often wise to put the change on the first line inside the condition so we can quickly see the effect
if fire_lock = 0
fire_lock = 1
rem tell the program the bullet has been fired
fire_bullet = 1
rem position the bullet at the ship's position
bullety = playery-20
bulletx = playerx
endif
Here's your coontrol_player code with my tweaks
control_player:
rem controls for moving player side to side
rem it will not let the player move out of the screen
if playerx < 600 and rightkey()=1 then inc playerx, 2
if playerx > 40 and leftkey()=1 then dec playerx, 2
rem store fire key input
oldfire = newfire
newfire = spacekey()
rem fire bullet if none exists
if newfire > oldfire
if bullet_fired = 0
bullet_fired = 1
rem position the bullet at the ship's position
bullety = playery-20
bulletx = playerx
endif
endif
return
I changed the flag name to bullet_fired because fire_bullet sounds like an instruction to fire a bullet instead of show that one has been fired.
Here's your update bullet code
update_bullets:
rem update player bullet
if bullet_fired
dec bullety, 7
rem if bullet passes out of screen it dies
if bullety < 0 then bullet_fired = 0
endif
return
This will work fine for now but when we come to add collisions there may be problems with moving 7 at a time because the bullet might skip over the enemy. This is eli's task but I haven't seen him post anything yet.
ARE YOU OUT THERE ELI?