Click to generate a new map.

About: This is a rectangular map generator I coded for a dungeon crawler project.

  • The grid is a matrix of Points, containing an x and y pointing to the upper-left corner of the current “Room”.
  • The algorithm starts by placing a room at (0,0), with a right-side Exit:
  1. Evaluate the current room’s exit(s):
  2. Check if the entry point is occupied, put a connecting exit in the pre-existing room
  3. If the entry point is open, place a new room.
  4. Repeat
  • When randomly placing a new room, a list of possible dimensions for the room is constructed:
  1. Starting from the entry point, maximize a 3×3 square that does not collide with any existing rooms:
  2. Loop and add all possible dimensions that fit within the maximized square.
  3. Randomly pick a possible room dimension.
  • The “placeRoom” method dictates the algorithm’s behavior. It can be adjusted to produce maps that feature only 1×1 rooms, or have more tunnel like shapes.

The source code can be viewed and downloaded here.


This file requires Adobe Flash Player (Standalone) to run, or a browser with Flash Player installed.

Click here to Download Procedurally Generated Dungeon.swf

3 Comments

Shuriken55 · February 12, 2016 at 7:43 am

Sometimes it generates too small rooms. If you have function what randomly chooses if new room will be generated, you should put one more check in “if” operator, like if(currentRoom < maxRooms && Random.nextBoolean()){/*generate new room there*/}

Overall, good job on this one! 😀

    Michael · February 12, 2016 at 5:23 pm

    I believe I did do something like that for my Slush Dungeon prototype!

Slush Dungeon is Dunzo | Michael Moy · October 13, 2015 at 7:15 pm

[…] Random MapGen […]

Leave a Reply