My goal is to create a game mechanic where if the player collides with an enemy from the side, it results in either losing a life or ending the game. However, if the player jumps on top of the enemy, the enemy will disappear.
When the player touches the enemy while they are both on the ground (player's y-axis equals the enemy's y-axis)...
player.y == enemy.y
And
When the player jumps on top of the enemy (player's y-axis is greater than the enemy's y-axis)...
player.y > enemy.y
Here is the current code I have implemented so far...
Level.prototype.playerTouched = function(type, actor) {
if (type == "enemy" && this.status == null && player.y == enemy.y) {
this.status = "lost";
this.finishDelay = 1;
} else if (type == "enemy" && player.y > enemy.y) {
this.actors = this.actors.filter(function(other) {
return other != actor;
});
}
};