Detecting collisions

We don't need to detect everything bumping into everything else. Specifically we need to detect the following three cases:

  • An alien bumping into the player- resulting in losing a life
  • The alien laser bumping into the player resulting in losing a life
  • The player's laser bumping into an alien resulting in the score going up, a particle effect explosion and the dead alien being respawned.

In the update method of the PhysicsEngine class change the return statement as highlighted next

// This signature and much more will change later in the project boolean update(long fps, ArrayList<GameObject> objects, GameState gs, SoundEngine se, ParticleSystem ps){ // Update all the game objects for (GameObject object : objects) { if (object.checkActive()) ...

Get Learning Java by Building Android Games - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.