Performing the checks
We are really close to being able to play our game, albeit with simplified collision detection. First add some methods that handle what happens when certain collisions are detected and then see how we actually use our CD
class.
Helper methods
First of all, we need a couple of helper methods to respond, when we detect various types of collisions.
We need a method for when the ship is destroyed and a method for when an asteroid is destroyed. The next two subsections cover this.
Destroying a ship
The death of a ship can be detected in two places, so it makes sense to add a method to handle the events that follow. In this next method, we reset the ship's location to the center of the map, play a sound, and decrement numLives
.
If numLives
is equal to zero, set levelNumber
back to one, numLives
to three, call createObjects()
to redraw a level, pause the game, and then play a sound suitable to let the player know that he is starting again.
Now, add the lifeLost
method to the AsteroidsRenderer...