I'm making a game engine in javascript for Educational purpose.
I already have the collision detection and collision response parts and are working fine, but i want to let the user define his action as a response to a collision. For example when a bullet collides with an enemy before the separation happens, i want to call a function which will kill the enemy.
I've been thinking of several methods, like:
- define a map in which the user will register a function for each collision that he wants to alter
- when a collision happens, call for each objects, in the collision, their "onCollide" function and based on the object sent as parameter a certain action will be performed.
But i don't know if these are good, or if there are other better solutions. So the question is, how do i implement this ?