Book Image

Mastering Android Game Development

By : Raul Portales
Book Image

Mastering Android Game Development

By: Raul Portales

Overview of this book

Table of Contents (18 chapters)
Mastering Android Game Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
API Levels for Android Versions
Index

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 some sprites that do not trigger collisions. This is done using BodyType.None.

We are going to use circular bodies for the asteroids and the player, and rectangular ones for the bullets.

Since we have a list of bodies that can collide, if a ScreenGameObject...