Jump to content
  • Advertisement
Sign in to follow this  

Room Based Euclidean Map

This topic is 1981 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all,


I have been stuck on this problem for about 2 weeks, and I think I have hit every brick wall possible, so alas  find myself here. I am currently creating a 2D rogue-like game (c++) with map elements not to dis-similar to the game Rogue Legacy. The level map is comprised of different rooms of different sizes that have entrances/exits to rooms that are adjacent. It's a little hard to explain, but hopefully this picture of Rogue Legacy which shows the game map will help.


And here is a crude paint drawing (where green arrows are entrance/exits)




Currently I am generating a map using a modified pathfinding algorithm which gives me my desired layout of rooms. 




I currently run the map generation store the rooms in a 2D array. Once all of the rooms have been generated, I then run through the array and place portals (entrance/exits) in the relevant rooms and set their destination room.


This works perfectly at the moment, where all the rooms are the same size. However adding larger rooms that can have more than the standard 4 portals (Left,Right,Up and down) is turning out to be a little tricky, as I am having trouble calculating the destination room and/or the position in that room.



Any help would be greatly appreciated, if you need anymore information just let me know :).

Edited by dsm1891

Share this post

Link to post
Share on other sites
You could make your room "portals" as vectors:

vector <int> portal[4];

where the [4] is the 4 cardinal directions. The vector would hold all the "room numbers" associated with that direction.
For example:

room (0,1) has 0 portals N, 1 portal S (room (2,2)), 2 portals E (room (0,2)), and 2 portals W (room (0,0) and room (1,0))

I don't really know how you are accounting for your rooms, but this should give you something to think about.

Share this post

Link to post
Share on other sites
When considering Rogue Legacy, there are a few things to consider first (the following is based on observation, not being involved in the game). The individual rooms are not randomly generated. There is a (large) set of handmade rooms available. These rooms have several exit locations. These exit locations can be 'open' or 'closed'. Exits in 'closed' state seal off an (again handmade) area of the room with blocking tiles.
Each room has an integer size in map-tiles (I believe from 1x1 to 3x3, although I haven't played the game for a while). One map-tile is always NxM room-tiles big (the actual number does not matter, the point is you can easily fit rooms together in a map like that and exits are always in the center of a map-tile edge).

These design decisions make a Rogue Legacy-like map generation actually a lot easier. In pseudo code:
Place the starting room.
While the map is not big enough:
   Pick a random 'closed' exit E in any room already placed
   Pick a random room R from the library of possible rooms (all exits of this new room are 'closed')
   Pick a random exit E' (opposite direction of E) of R and try to place it in the map so that E and E' connect
   If that is possible without overlapping with existing rooms in the map: (*)
      Place R in the map
      Iterate over all other 'closed' exits of R
         If there is a corresponding 'closed' exit in the room in that direction, set both to 'open'
The check at (*) is actually extremely simple. Since everything is neatly on map-tiles, there is exactly one way how you could place the room in the map and the check could be as simple as a bitmap with one bit for each map-tile. Edited by BitMaster

Share this post

Link to post
Share on other sites

I really like the technique described above, and I've seen several other techniques described in various articles scattered across the web, but if you want to experiment I have an idea that should work.


First add all the rooms to the map, use a force based system to give some separation between the rooms.


Then walk the map vertically and horizontally shooting rays from each room, record the first room the ray intersects.


At the end of this, for each room you will have a list of rooms that it could link to below and to the right, and a count of how many possible links exist.


If this count is greater than a pre-set value, randomly pick one of the rays and add doors at both ends.


At the end check all the rooms to make sure they have at least one door. If not pick a ray at random and add doors. If no rays exist, remove the room.


By using a ray based system, rooms can be any shape you like. As long as you can find a ray - shape intersection test, it will work.


I also have some ideas for corridors, but that's for another post.

Share this post

Link to post
Share on other sites


Sorry for the late reply I kinda forgot about this thread.


The problem with the suggested methods above is that I first create a paths, then traverse the nodes (A.K.A the matrix along the path) populating each position with a random room.


You can read about my map generation algorithm (RBES) here: http://www.davidmarshall.info/rbes.html


but the TL;DR version is:

populate the map assuming all rooms are the smallest size

once the population of the map has finished, check and deal with overlapping. Then check the size of the rooms and link to adjacent rooms/subrooms for how ever many subrooms are on the parameter.

(a subroom being the space a minimum room could fit into)


Sorry for late reply, but I hope this will help somebody in the future :)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!