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\$
7
  • \$\begingroup\$ What do the numbers 1, 2, and 6 mean here? \$\endgroup\$
    – DMGregory
    Oct 11, 2021 at 16:05
  • \$\begingroup\$ They mean the zone number to go to. \$\endgroup\$ Oct 11, 2021 at 16:06
  • \$\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, 2021 at 16:17
  • \$\begingroup\$ @Philipp see my comment on the previous question, which is where the title of this new question was proposed as a refinement to that existing question. \$\endgroup\$
    – DMGregory
    Oct 11, 2021 at 16:18
  • \$\begingroup\$ Currently, I have edge exits and I also have objects in some of the zones that can exit to another zone. Also it is the zone index plus one. The zones can be laid out in a grid. \$\endgroup\$ Oct 11, 2021 at 16:21

1 Answer 1

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\$
1
  • \$\begingroup\$ If this solved your problem, remember to mark the answer as accepted by clicking the checkmark icon on the left. If you'd like the answer to be helpful for future readers trying to solve similar problems, you should consider editing the post to include more detail about how to implement such a structure. \$\endgroup\$
    – DMGregory
    Jul 12, 2022 at 22:16

You must log in to answer this question.

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