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;
zone[1].link_down = 1;
zone[1].link_left = 6;
zone[5].link_right = 2;
An example of exiting around the edges:
if (player.x > zone[current_zone].map.width-1)
{
exit = zone[current_zone].link_right;
if (exit)
{
if (exitmaplink(exit, 1))
return;
}
player.x = zone[current_zone].map.width-1;
}