Workshop › Zelda-style Dungeon › Step 12 of 22
A far enemy wanders: one pixel a frame in its direction, and every now and then (or when it bumps into a wall) it picks
a new random direction. move tells us when it bumped.
```js
} else {
// Far: wander, turning at random now and then or when a wall is in the way.
e.turnIn -= 1
const stuck = move(e, e.dir[0], e.dir[1])
if (stuck || e.turnIn <= 0) {
e.dir = Object.values(DIRS)[Math.floor(Math.random() * 4)]
e.turnIn = 40 + Math.floor(Math.random() * 60)
}
}
```turnIn counts down the frames until the next turn.Object.values(DIRS) is the list of the four directions; a random one is picked.In the chase block, add an else that wanders when far.
Skills: Velocity and gravity, Game states