Workshop › Mario-style Platformer › Step 31 of 37
Touching an enemy has two outcomes, and the difference is only direction. Coming down onto its head is a stomp: the enemy is squashed and the player bounces up. Anything else hurts. The rule is forgiving: falling, with the feet still in the top half of the enemy.
```js
if (line[col] === 'e') enemies.push({ x: x + 2, y: y + 4, w: 28, h: 28, vx: 0, vy: 0, dir: -1, alive: true })
if (!enemy.alive || !overlaps(player, enemy)) continue
// A stomp: falling, with the feet still in the top half of the enemy. Anything else is a hit.
const stomp = player.vy > 0 && player.y + player.h < enemy.y + enemy.h / 2
if (stomp) {
enemy.alive = false
player.vy = JUMP * 0.6
} else {
die()
return
}
```alive: true; dead ones are skipped.stomp is true when falling (vy > 0) and the feet (y + h) are above the enemy's middle (y + h / 2).die().loadLevel, add alive: true to the enemy.update, replace the three lines inside the enemy loop with the new ones.Skills: Collision detection, Game states
← Enemies hurt Squashed enemies are gone →