Workshop › Zelda-style Dungeon › Step 17 of 22

The locked door

What we are doing

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)
}
```

What it means

Your turn

In update, after picking things up, open a door in front of you.

Skills: Game states

All steps

  1. A room
  2. The hero
  3. The game loop
  4. Walk
  5. Walls
  6. A touch pad
  7. Next room
  8. The sword
  9. Enemies
  10. Strike!
  11. They chase you
  12. They wander
  13. Ouch
  14. Blinking and hearts
  15. Keys and hearts
  16. A world that remembers
  17. The locked door
  18. A timer
  19. Game over
  20. The stairs out
  21. Best time
  22. Build it yourself: cleared rooms