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

Chapter 4. Collision Detection

In most games we need to detect when objects intersect with each other to trigger actions; this is called collision detection. We will use it to detect when a bullet hits an asteroid (to destroy it) and when the player is hit by an asteroid (to end the game). This detection can be done in a discrete or in a continuous way, and it can involve different types of shapes. We will use discrete detection with rectangular and circular shapes.

As mentioned in Chapter 1, Setting Up the Project, we are not going to do any Physics simulation. That is a completely separate topic and it is long enough to deserve its own book.

We will also discuss optimization techniques and implement one method called spatial partitioning that splits the area into smaller ones based on object density.

As a side note, all the concepts in this chapter can be easily extrapolated to collisions in 3D.