Now that dying is a thing that objs can do, they should be able to compel each other to do it. This will involve the collisionCallback that each obj has.
The easiest thing to do would be rock-scissors-paper style collisions: if (obj.name === 'rock' && this.name === 'paper') { this.die() } or whatever. But we want things a little more sophisticated than that: If the player is on top of the mob, the mob dies. Otherwise, the player dies. That might involve reading which points did the colliding, or it might just mean comparing the y coord of the objs. At any rate, these can all be handled in the collision callback function.
What we usually care about the most is player-obj collisions (as opposed to obj-obj collisions that don't involve the player)... So I think the easiest thing to do is for the non-player to do most of the logic when there's a collision. Otherwise, the player obj will end up with a mess of switch statements that will get difficult to maintain.
Notes
This might be a good time to implement things like obj.mortal and/or obj.collidable. Maybe obj.murderous.
While we're at it... There's no reason that this issue couldn't also encompass headbutting blocks to pieces. They're already collidable.
TL;DR
Summary
Now that dying is a thing that objs can do, they should be able to compel each other to do it. This will involve the
collisionCallback
that each obj has.The easiest thing to do would be rock-scissors-paper style collisions:
if (obj.name === 'rock' && this.name === 'paper') { this.die() }
or whatever. But we want things a little more sophisticated than that: If the player is on top of the mob, the mob dies. Otherwise, the player dies. That might involve reading which points did the colliding, or it might just mean comparing the y coord of the objs. At any rate, these can all be handled in the collision callback function.What we usually care about the most is player-obj collisions (as opposed to obj-obj collisions that don't involve the player)... So I think the easiest thing to do is for the non-player to do most of the logic when there's a collision. Otherwise, the player obj will end up with a mess of switch statements that will get difficult to maintain.
Notes
obj.mortal
and/orobj.collidable
. Maybeobj.murderous
.