Resolving the outcome of a collision between 2 sprites

Hey Crew,

This isn’t another ‘How do I do collision detection?’. This more a question of how to resolve the outcome once a collision has been detected.

For Example, I normally have the flow:

  • Update Player Sprite
  • Update Enemy Sprites
  • Check collision between Player & Enemies

But then this is when my thinking gets blurred. The player will have rules on what do to if hit by a enemy and an enemy will have rules if hit by the player, I am just not sure on where the rules should live. Ideally in each class of sprite, but then I can’t figure out how to share it.

Is anyone doing anything funky I am not aware of?

Cookie

A rough example:


public class CollisionDetector {
   public void addCollisionHandler(CollisionHandler handler);
}

public interface CollisionHandler {
   onCollision(...);
}

public class PlayerCollisionHandler implements CollisionHandler {
...
}

Ahh, I like your thinking :slight_smile: