Book Image

Android Game Programming by Example

By : John Horton
Book Image

Android Game Programming by Example

By: John Horton

Overview of this book

Table of Contents (18 chapters)
Android Game Programming by Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
7
Platformer – Guns, Life, Money, and the Enemy
Index

Precise collision detection with an asteroid


We did this last because there is a more complicated final step. As in the border detection, we will need to translate and rotate our object's vertices. However this time, we will need to do it for two objects.

Furthermore, once we rotated and translated the asteroid's vertices, we will need to handle them in pairs of vertices that form a line. These are lines that we will test against each and every vertex from the other object. This test is of course our crossing number method that we discussed.

We need to do all of this within the body of the if (distance < cp1.radius + cp2.radius) { ...}, where we previously just set the collided Boolean to true.

There is quite a lot of code, so we will split it into chunks and see what is going on at each stage. Also, the code indentation will not always be consistent from block to block in order to format it in the most readable way possible.

The next few blocks of code are the entire contents of the aforementioned...