Collisions
Well, so far so good. However, we haven't implemented any collision handling. Luckily, LibGDX contains really useful tools to check for collision between the shapes that we are using. This is going to make our lives a lot easier.
The one class we will use is the Intersector
class. To find out more, visit http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Intersector.html and take a look at its API, you will see all sorts of useful methods there. However, we are only going to use two of them:
boolean overlaps(Circle c1, Circle c2) boolean overlaps(Circle c, Rectangle r)
These will return true
if the shapes overlap.
So, let's add a method to our Flower
class that will take an instance of Flappee
in and check the collision areas, as follows:
public boolean isFlappeeColliding(Flappee flappee) { Circle flappeeCollisionCircle = flappee.getCollisionCircle(); return Intersector.overlaps(flappeeCollisionCircle, ceilingCollisionCircle) || Intersector.overlaps(flappeeCollisionCircle...