Workshop › Pac-Man-style Maze Chase › Step 4 of 42
The pellets get eaten, so they must be state, not map. Each pellet is named by a key like '8,15', and all keys go in
a Set: a collection where each value is in at most once, with quick has, add and delete.
```js
let pellets // keys of the tiles that still have a pellet
let powers // keys of the tiles that still have a power pellet
const key = (col, row) => col + ',' + row
function fillPellets() {
pellets = new Set()
powers = new Set()
MAZE.forEach((line, row) => {
;[...line].forEach((ch, col) => {
if (ch === '.') pellets.add(key(col, row))
if (ch === 'o') powers.add(key(col, row))
})
})
}
function reset() {
fillPellets()
}
reset()
```key(8, 15) gives '8,15': one string per tile.new Set() is an empty set; add puts a key in.fillPellets walks the map like draw does and collects every . and o.reset() will set up a whole new game; for now it fills the pellets. It runs once before the loop starts.COLS, leave an empty line and write the two variables, key, fillPellets and reset.requestAnimationFrame(loop), write reset().Skills: Arrays and objects, Game states
← Draw the walls Draw the pellets →