Random Map Generator

Made: October 2013
Dev Progress: 100%

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.

3 thoughts on “Random Map Generator

  1. Pingback: Slush Dungeon is Dunzo | Michael Moy

  2. 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! 😀

Leave a Reply