O'Reilly logo

Android Game Programming by Example by John Horton

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

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 ...

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