Coding the PhysicsEnginePlayMode class
This is the class that will do all the collision detection. In this game, there are several collision events we want to watch out for:
- Has an invader reached the left- or right-hand side of the screen? If so, all the invaders need to drop down one row and head back in the other direction.
- Has an invader collided with the player? As the invaders get lower, we want them to be able to bump into the player and cause a life to be lost.
- Has an invader bullet hit the player? Each time an invader bullet hits the player, we need to hide the bullet, ready for reuse, and deduct a life from the player.
- Has a player bullet hit an invader? Each time the player hits an invader, the invader should be destroyed, the bullet hidden (ready for reuse), and the player's score increased.
This class will have an initialize
function that the GameScreen
class will call to prepare for detecting collisions, a detectCollisions
function that...