11.2. Collision-handling

Here’s an overview of how the Pop Framework handles collisions.

  1. Make a utility class for holding pairs of critters, and let this class specify which critter has the priority to control the behavior of a collision.

  2. Maintain a collection of all pairs of critters that might meaningfully collide.

  3. During each game step, iterate through this collection of candidate pairs.

  4. For each candidate pair, collide the critters by letting the higher priority critter call its collide method on the other.

  5. A critter’s collide(pcritter) method checks if it’s touching pcritter, and if so, changes the two critters’ velocities and positions in a physically reasonable fashion. Child classes may override collide to alter the behavior.

We said a bit ...

Get Software Engineering and Computer Games 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.