1
\$\begingroup\$

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: 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;
        }
\$\endgroup\$
9
  • \$\begingroup\$ In future, please edit your existing question to refine its focus instead of posting a new one about the same topic. \$\endgroup\$
    – DMGregory
    Oct 11 '21 at 15:27
  • \$\begingroup\$ What do the numbers 1, 2, and 6 mean here? \$\endgroup\$
    – DMGregory
    Oct 11 '21 at 16:05
  • \$\begingroup\$ They mean the zone number to go to. \$\endgroup\$ Oct 11 '21 at 16:06
  • \$\begingroup\$ @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. \$\endgroup\$
    – Philipp
    Oct 11 '21 at 16:17
  • \$\begingroup\$ 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? \$\endgroup\$
    – DMGregory
    Oct 11 '21 at 16:17
0
\$\begingroup\$

I've found a solution to the problem, I've made a structure called a zone which is a collection of maps.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .