Dungeon Corridors


Author: Adam Stagg

When generating dungeons, we go room by room. When the second room is spawned, we need some way to connect this room to the previous room so that the player is able to walk through the entire dungeon. To do this, we will need to spawn corridors. When thinking about HOW to spawn these, we need to think about the potential cases we will have when spawning. We will have directly up, down, left, or right, and we will also have cases where corridors will need to turn in the middle. Knowing this, we can determine that we will have 12 potential options for corridors.



To solve this, we initially check if we have any overlap in a room. If we are able to make it to the next room with only a straight corridor, we will try that. If the maximum X of one room is greater than the minimum X of the second, we know we have overlap on the X axis. This also applies to the Y axis. If we do NOT have any overlap, we know we must make a corridor that turns. We will check which of the four quadrants we are in, randomly pick if we go vertical first or horizontal first, and then calculate a position that two corridors can meet in. By making two of these corridors march towards a meeting point, we have essentially turned two corridors into one. The end result is a dungeon that ensures every room has at least one connection to it.

Leave a comment

Log in with itch.io to leave a comment.