Workshop › Pac-Man-style Maze Chase › Step 20 of 42
Every frame, after the player, advance each ghost with chooseGhost. One catch: if the player's move just cleared
the maze, everyone was placed again, so the ghosts skip that frame.
```js
function update() {
const startLevel = level
advance(player, choosePlayer)
if (level !== startLevel) return
for (const g of ghosts) advance(g, chooseGhost)
}
```startLevel remembers the level before the player moves; a different level afterwards means a new maze was set up.advance moves the ghosts; only the choose function differs.Replace the body of update as shown.
Skills: The game loop, Game states
← A ghost never turns back The ghost hunts you →