Workshop › Zelda-style Dungeon › Step 17 of 22
Walking into a locked door D with a key opens it for good: the key is used up, the door becomes floor, and the world
remembers it.
```js
// A locked door right in front of you opens with a key.
const [dx, dy] = player.dir
const fc = Math.floor((cx + dx * T * 0.6) / T)
const fr = Math.floor((cy + dy * T * 0.6) / T)
if (tiles[fr] && tiles[fr][fc] === 'D' && keysHeld > 0) {
keysHeld -= 1
tiles[fr][fc] = '.'
taken.add(room.rx + ',' + room.ry + ',' + fc + ',' + fr)
}
```tiles[fr] && guards against a row outside the room (after a gap).taken too, so it stays open.In update, after picking things up, open a door in front of you.
Skills: Game states
← A world that remembers A timer →