Menu
IDS - Projectiles
Fire Projectiles
Adding the ability to fire a projectile like a missile requires variables to hold the coordinate and vector of the missile. We will assume that there is only one missile launched, and that it is re-used once it runs off of the screen.
Upon hitting the fire button, we need to make sure that the current missile is not already travelling on screen. So we ask if it's coordinate is off screen. If it is off screen, then it is ready to fire again. In that case, the missile is immediately set to be at the same coordinate as the players ship. Once the missile is set at that position, it's vector is also set accordingly. |
Fire Button
If the button is pressed, attempt to fire
If the location of the missile is off screen then we can assume that it is ready to fire and so we set its location to be the same as the ship. However, if the location is already on screen, then the missile is still travelling and is not yet ready to be fired again. |
Flyinig Missile
All movement happens within the forever loop. Erase the current location of each object, and then move them according to their vectors.
If the missile is on screen, then move the missile by the vector. In a simple space invaders game, the vector is only up, so the vector is assumed to have a Y value of -1. |
Collision
Note: a missile that hits an alien should also be removed from the screen here