Spawning bullets
We need a way to spawn bullets from both the player and each of the invaders. The solutions to both are very similar but not identical. We need a way to allow GameInputHandler
to spawn bullets when a keyboard key or gamepad button is pressed, and we need InvaderUpdateComponent
to use its already existing logic to spawn bullets.
The GameScreen
class has a vector
holding all the GameObject
instances, so GameScreen
is the ideal candidate to move a bullet into position and set it moving up or down the screen, depending on who or what triggered the shot. We need a way for the GameInputHandler
class and InvaderUpdateComponenet
to communicate with the GameScreen
class, but we also need to restrict the communication to just spawning bullets; we don't want them to be able to take control of any other part of the GameScreen
class.
Let's code an abstract class that GameScreen
can inherit from.
Coding the BulletSpawner class
Create a new header file in the...