Workshop › Pac-Man-style Maze Chase › Step 23 of 42
A waiting ghost counts its waiting down by one every frame instead of moving, and is released when it reaches 0. So
pink comes out after 2 seconds, orange after 5 and cyan after 8.
```js
for (const g of ghosts) {
if (g.waiting > 0) {
g.waiting -= 1
if (g.waiting === 0) release(g)
continue
}
advance(g, chooseGhost)
}
```continue skips the rest of the loop for it: it does not move this frame.release puts it on the exit.In update, replace the one-line ghost loop with the new loop.
Skills: Game states, The game loop
← Four ghosts in the house Scatter or chase? →