O'Reilly logo

Android: Game Programming by Raul Portales, John Horton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required