Workshop › Pac-Man-style Maze Chase › Step 15 of 42
When a step ends, the mover arrives on a tile. arrive removes the pellet there (10 points) or the power pellet
(50 points). delete tells whether something was removed, so a tile scores only the first time.
```js
let score
let level
score = 0
level = 1
e.row += e.dir[1]
arrive(e)
}
function arrive(e) {
if (e !== player) return
const here = key(player.col, player.row)
if (pellets.delete(here)) score += 10
if (powers.delete(here)) score += 50
}
```advance calls arrive right after the tile changes.advance too.Set.delete returns true if the key was there (and removes it), false if not: eating and "was there a pellet?"
in one call.let player write let score and let level; in reset, set them to 0 and 1 above fillPellets().advance call arrive(e), and under advance write arrive.Skills: Game states, Collision detection
← Swipes on a phone Show the score →