Workshop › Pac-Man-style Maze Chase › Step 22 of 42
Four ghosts join the game. Each description gets a corner (used soon) and a delay: how many frames it waits in the
house. The ghosts now start inside the house; release puts one on EXIT, heading left, and the red one, which
waits 0 frames, is released at once.
```js
const GHOSTS = [
{ name: 'red', color: '#ef4444', corner: { col: 18, row: 0 }, delay: 0 },
{ name: 'pink', color: '#f9a8d4', corner: { col: 0, row: 0 }, delay: 120 },
{ name: 'orange', color: '#fb923c', corner: { col: 0, row: 20 }, delay: 300 },
{ name: 'cyan', color: '#22d3ee', corner: { col: 18, row: 20 }, delay: 480 },
]
ghosts = GHOSTS.map((g, i) => ({ ...g, col: 8 + (i % 3), row: 9, dir: STOP, progress: 0, frames: 10, waiting: g.delay }))
for (const g of ghosts) if (g.waiting === 0) release(g)
}
// Out of the house: the ghost starts on the tile above it, heading left.
function release(g) {
Object.assign(g, { col: EXIT.col, row: EXIT.row, dir: [-1, 0], progress: 0 })
}
```map((g, i) => ...) also gives the position i; 8 + (i % 3) spreads the ghosts over the house's columns 8, 9, 10.waiting starts at the ghost's delay.Object.assign(g, { ... }) writes several fields into an existing object at once.GHOSTS line with the four descriptions.placeActors, replace the ghosts line with the two new lines.placeActors, write the comment and release.Skills: Game states, Arrays and objects
← The ghost hunts you One by one out of the house →