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:
- Evaluate the current room’s exit(s):
- Check if the entry point is occupied, put a connecting exit in the pre-existing room
- If the entry point is open, place a new room.
- Repeat
- When randomly placing a new room, a list of possible dimensions for the room is constructed:
- Starting from the entry point, maximize a 3×3 square that does not collide with any existing rooms:
- Loop and add all possible dimensions that fit within the maximized square.
- 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.
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 […]