Skip to content

Instantly share code, notes, and snippets.

@MarioLiebisch
Created June 5, 2015 09:58
Show Gist options
  • Save MarioLiebisch/e7b5202db7387b3a9698 to your computer and use it in GitHub Desktop.
Save MarioLiebisch/e7b5202db7387b3a9698 to your computer and use it in GitHub Desktop.
Basic Procedural Dungeon Generation (e.g. for Rougelikes)

#Basic Procedural Random Dungeon Generation

  • Create one set holding used rooms.
  • Create one set holding open ends.
  • Place a random room, add it two both sets and flag it as the entrance.
  • Repeat as long as you don't have your intended number of rooms:
    • Randomly pick a used room ("current room").
    • Pick a random direction.
    • If the chosen direction is the border of the map, continue the loop.
    • Remove the current room from the open ends.
    • If there's no room in the target direction, add a new room.
      • Add the new room to the open ends.
      • Add the new room to the used rooms.
      • Decide randomly whether the new room contains a hidden key. If it does, add one key to the available keys.
    • Connect both rooms using a door.
    • Decide randomly whether the door is locked (if keys are available).
      • If it's locked, remove one available key again.
  • Pick a random open end and make it a boss room and remove it from open ends.
  • Pick a random open end and make it a treasure room and remove it from open ends.
  • Pick a random open end and make it a shop and remove it from open ends.
  • To make the dungeon more random, iterate over all remaining open ends:
    • Decide randomly whether you add another connection to a nearby normal room or do nothing.
    • Other key items or tools allowing you to pass some area as well as obstacles can be added the same way.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment