O'Reilly logo

Mastering Android Game Development by Raul Portales

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

Mixed collision detection

We have seen that a single shape does not fit all cases, so we are going to update our game to allow us to define which body shape each ScreenGameObject uses for collisions. For this, we are going to create an enum of body types and have a variable to store that information in ScreenGameObject.

The enum BodyType is as follows:

public enum BodyType {
  None,
  Circular,
  Rectangular
}

In the case of sprites, we will add a parameter to the constructor that specifies body type. Note that we have a special type called None. This is used for sprites that do not collide with others. While there are none of those in our game yet, other types of games can have them—for example, floor tiles on a dungeon crawler.

Note

We may want to have ...

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