In this video I go over my approach to breaking down a large problem like procedural dungeon generation into an algorithm of smaller more simple steps. I follow the highlevel steps outlined below to randomly create a topdown dungeon with various rooms, hallways and chambers. The tools I used to create this video are as follows.
Unity 3d
Visual Studio
POLYGON Art assets from Synty Studios
The algorithm can be broken down into three components, the dungeon, the room, and each opening within a room. Each component will follow a simple set of steps until the dungeon is finished being generated.
Dungeon’s Perspective
Step 1: Spawn a room
Step 2: Get the first available room that has unconnected openings
Step 3: Tell the room to spawn its’ adjacent chambers
Step 4: Wait until the room’s openings have spawned
Step 5: Add Created Rooms to the dungeon
Step 6: Repeat 2 – 6 until there are no more unconnected openings
Room’s Perspective
Step 1: Get all the room openings
Step 2: Iterate over each opening and spawn adjacent chamber
Step 3: Wait until all adjacent chambers are spawned and are in a valid state
Step 4: Notify dungeon new rooms are ready
Room Opening Level
Step 1: Get available pieces from the dungeon to spawn
Step 2: Spawn a connected piece
Step 3: Wait for the validation period to complete
Step 4: Mark the opening as connected and notify the
room that a connected chamber is ready
New Room Validation
A room becomes invalid if it intersects another room
If it becomes invalid then the room will destroy itself and notify the connection point to try a different piece.
If all the pieces are attempted and nothing will fit, then the connection point will close off the room with a wall instead.
Broken Knights Games
Web https://www.brokenknights.com
Instagram / brokenknightsgames
Twitter @Broken_Knights
Credits:
Images obtained from www.textures4photoshop.com