Workshop › Pac-Man-style Maze Chase › Step 24 of 42
Ghosts that always chase would bunch up in a line. So they switch modes on a clock: in every 27-second cycle, the
first 7 seconds are scatter (each ghost goes to its own corner, a breather for you), the rest is chase. One
counter and % make a repeating schedule.
```js
const SCATTER = 420 // frames of scatter at the start of every 27-second cycle
const CYCLE = 1620
let clock // frames played on this life, for the scatter / chase cycle
clock = 0
function mode() {
return clock % CYCLE < SCATTER ? 'scatter' : 'chase'
}
function update() {
clock += 1
```clock counts frames since the actors were placed; placeActors sets it back to 0.clock % CYCLE goes 0, 1, ... 1619 and starts again: the place in the current cycle. Below SCATTER (7 seconds)
it is scatter time.GHOSTS write SCATTER and CYCLE; under let level write let clock.placeActors, at the end, write clock = 0.target, write mode.update, write clock += 1 and an empty line.Skills: Game states
← One by one out of the house Every ghost to its corner →