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

Get Android Game Programming by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.