Workshop › Bomberman-style Arena › Step 30 of 42
Enemies move like the player, from tile to tile with a target and moveTo, only slower. On each tile they list the
ways they can go and pick one at random.
```js
const ENEMY_SPEED = 0.05
function updateEnemy(e) {
if (!e.target) {
const options = Object.values(DIRS).filter(([dr, dc]) => walkable(e.y + dr, e.x + dc))
if (options.length === 0) return
e.dir = options[Math.floor(Math.random() * options.length)]
e.target = { r: e.y + e.dir[0], c: e.x + e.dir[1] }
}
moveTo(e, ENEMY_SPEED)
}
for (const e of enemies) updateEnemy(e)
```options keeps the four directions whose next tile is walkable; with none, the enemy waits.Math.floor(Math.random() * options.length) is a random index: Math.floor rounds down, so 0 to length − 1.e.dir and the next tile the target.SPEED write ENEMY_SPEED.function hurt() { write updateEnemy.update, under updatePlayer(), write the enemies line.Skills: Game states