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 {

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.


We may want to have ...

Get Android: Game Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.