Workshop › Pac-Man-style Maze Chase › Step 39 of 42
The player must see which ghosts are safe to eat: scared ghosts are drawn blue, and in the last two seconds they flash white, a warning that the fright is ending.
```js
// Blue while scared, flashing white in the last two seconds.
const flash = scaredFor < 120 && Math.floor(scaredFor / 10) % 2 === 0
ctx.fillStyle = g.scared ? (flash ? '#e5e7eb' : '#3b82f6') : g.color
```scaredFor / 10 rounded down changes every 10 frames; % 2 === 0 is true every other time: on for 10 frames, off
for 10.? : inside another: scared → (flash → white, else blue), not scared → the ghost's own color.In draw's ghost loop, replace the fillStyle line with the comment and the two new lines.
Skills: Drawing on a canvas
← Eat a scared ghost Harder levels →