# Procedural dungeon rooms and corridors on a TileMap ```{raw} html ▶ Run in browser ``` **Tags:** `2d` `tilemap` `procgen` `dungeon` `collision` Places non-overlapping rooms at random, links each to the previous one with an L-shaped corridor, and renders the result as wall and floor tiles. Generation is a pure function of the seed, so the same number always yields the same dungeon. A player dot walks the map with grid-based wall collision. Controls: WASD / arrows move, R rolls a new seed, [ / ] step the seed, Esc quits. Headless self-check: uv run python examples/features/2d/procgen_dungeon.py --test ## What it demonstrates - A self-contained, deterministic dungeon generator (`generate_dungeon`) you can lift straight into a game: random.Random(seed) in, grid + room list out. - Reachability by construction: every room is carved, then connected to the one placed before it, so the whole floor is one region. - TileMapLayer.set_cells(): the entire grid rewritten in one vectorised call, which is what makes instant regeneration cheap. - Collision against the grid, not against physics bodies: the player's box is tested per axis with `can_stand`, the pattern roguelikes and grid games use. Run: uv run python examples/features/2d/procgen_dungeon.py ## Source ```{literalinclude} ../../examples/features/2d/procgen_dungeon.py :language: python :linenos: ```