Workshop › Pac-Man-style Maze Chase › Step 9 of 42
advance(e, choose) moves anything by one frame. At the center of a tile (progress === 0) it lets choose decide
the direction. Then progress grows by one; after frames frames the step is done: the tile changes and progress
starts again from 0.
```js
// One frame of movement. Directions are only chosen at the center of a tile, by `choose`.
function advance(e, choose) {
if (e.progress === 0) choose(e)
if (same(e.dir, STOP)) return
e.progress += 1
if (e.progress < e.frames) return
e.progress = 0
e.col = wrap(e.col + e.dir[0])
e.row += e.dir[1]
}
```choose(e) calls whatever was passed.return ends the function early.progress reaches frames does the tile change; the column is wrapped for the tunnel.Under reset, leave an empty line and write the comment and advance.
Skills: Game states, Functions
← What a mover remembers Move every frame →