# How do I carve rooms and corridors into my map to connect exits placed at the edges?

I'm creating an adventure/RPG top down game where the map is randomly generated divided into zones. A major problem I'm having trouble figuring out is creating exits placed at the edges. The game is programmed in C.

My inspiration is the Windows game Indiana Jones and His Desktop Adventures:

The map here is composed of an 2D array containing smaller maps called zones. Each zone is connected to surrounding zones so when the player goes to the edge of the zone they will move to another zone.

My current solution is to use variables on each individual zone that are "links", but it may be too tedious to define each link for each zone. I'd like to find a better way than that.

I initialize the links like this (the numbers are the zone number) and they are connected:

zone[0].link_up = 2;


An example of exiting around the edges:

if (player.x > zone[current_zone].map.width-1)
{
if (exit)
{
return;
}
player.x = zone[current_zone].map.width-1;
}

• In future, please edit your existing question to refine its focus instead of posting a new one about the same topic. Oct 11 '21 at 15:27
• What do the numbers 1, 2, and 6 mean here? Oct 11 '21 at 16:05
• They mean the zone number to go to. Oct 11 '21 at 16:06
• @DMGregory The screenshot might look familiar, but this question is actually very different. The previous one is about procedural generation, this one is about the technical implementation of map transitions. Oct 11 '21 at 16:17
• Do they follow any specific rule/pattern? For example, could we lay out the zones in a grid, where a zone connects only to the zones adjacent to it? Or are the links completely arbitrary? Also, it looks like these numbers are the zone index plus one — is that accurate? Oct 11 '21 at 16:17