Pattern for removal after collision

My game has a main player that fights against multiple (AI) opponents. I need a pattern for collision detection and removal of the damaged opponent (and the projectile that caused the damage.)

The simplest way, though not the most elegant way that I can think of, is to have the main game class create the player and multiple opponents, each with their respective locations. Each of these objects assigns a CollisionDetection object (a bunch of waitOn behavior handlers) to handle the collision, but what I don't see is a way for the resultant collision handler to remove the object from the scene.

Must I pass the scene object to each of the player and opponents so it can request its own removal? Must I centralize the logic to remove objects and have each collided object ask the system to remove it? Is there a pattern for a Collision Detection Manager of some sort?

Any similar game source code would be an ideal reference.

Torin...

[976 byte] By [torinwalker] at [2007-9-30 15:06:39]
# 1

Try adding all the "entities" you create to some master list at the same time you create them. When they collide and destroy each other, you can set a flag in the entitiy to note this fact. And every so often, have your logic go through the master list and set any destroyed objects to null so the garbage collecter comes and eats them. Done and done.

SheepNine

SheepNine at 2007-7-5 22:01:00 > top of Java-index,Other Topics,Java Game Development...
# 2

Create a Collisions set. When you detect a collision, add your collision object to that set.

When you're done with that step, pass the collisions set to the scene manager. The scene manager then goes through the set of collisions, and for each collision object, it removes the entities from the scene.

Of course this assumes that collision => removal.Things may collide but still need to remain in the scene sometimes, wouldn't they?

paulcw at 2007-7-5 22:01:00 > top of Java-index,Other Topics,Java Game Development...