switching walkable areas and a door

Started by antineff, Sun 21/08/2005 20:40:57

Previous topic - Next topic

antineff

Hi,

I know, that there were a lot of threads for similar problems but I couldn't make a solution for my prob out of them. Maybe a bright mind could give me a hint.

Imagine the following:

There is the middle room out of three rooms. Exits to the north and to the south. In the middle, theres a fence with a gate. I have WalkableArea(1) which is in the north of the path, I have WalkableArea(2) in the south and there is also WalkableArea(3) underneath the gate and at the borders of the unwalkable Area underneath the fence. This is mostly because of cosmetical reasons for keeping the character from running into the fence, when coming from the other side. The background image shows the open gate. The closed gate is defined as an object.

The first time, I enter this room, the gate is closed and I'm coming from the south, so WalkableArea(2) must be enabled, (1) and (3) must be disabled. When I open  the gate and leave it open, all three Areas must be and stay enabled. If I close the gate from the north (2) and (3) must be disabled and BE IN THE SAME STATE when I leave the room and return to it (All WalkableAreas are automaticaly enabled instead). If I leave to the south having the gate closed, (1) and (3) must be and stay disabled.

The only solution I found was using Global Variables and it was some kind of complicated. But I'm looking for a comfortable way since this seems to be a situation found in every adventure game at several places.

Thanks for help!
coming soon (or later, sorry!)

fred

Well, global variables are well suited for this kind of thing: keeping track of the game on a global level, including the status of rooms that the player isn't presently in.

If you really want to do without them, i guess your problem could be handled from the room script.

In the player enters screen (before fadein), do the following:

Code: ags


Ã,  if (IsObjectOn(GATE) == 0) 
Ã,  //GATE should be replaced by the number of the gate object
Ã,  {
Ã,  Ã,  //enable all walkable areas
Ã,  }
 
Ã,  else
Ã,  {
Ã, Ã,  Ã, int previous_room = character[EGO].prevroom; 

Ã, Ã,  Ã, if (previous_room == SOUTH) 
Ã, Ã,  Ã, //SOUTH should be replaced by the number of the room to the south
Ã, Ã,  Ã, {
Ã,  Ã, Ã,  Ã, //enable walkable areas accessible when entering from south
Ã, Ã,  Ã, }

Ã, Ã,  Ã, else if (previous_room == NORTH)
Ã, Ã,  Ã, //NORTH should be replaced by the number of the room to the north
Ã, Ã,  Ã, {
Ã,  Ã, Ã,  Ã, //enable walkable areas accessible from north only,
Ã, Ã,  Ã, }
Ã,  }



instead of creating new global variables, you can use the fact that the "previous room" variable and the state of the gate object (on or off) is already known to you.

About the player closing the gate while he's in the room, you can check whether theÃ,  character[EGO].y value is to the south or the north of the gate, and disable the correct walkable areas instantly when the player interacts with the gate object.

- fred

antineff

Sometimes you only have to write down a problem and the solution will come to you. After sending the thread the illumination came over me. :)

Thanks to fred anyway. This seems to be a well working solution, and I came to the same idea with the y-coordinate. But I used it to manage the whole thing, since the "Previous-Room-Solution" has the disadvantage that while developing the game it might be possible to put another room between the already connected rooms, and therefore you have to take care of the script. In the following I offer my solution which only affects the involved items:

First I define the state of the walkable areas when entering the room:

Room Editor / Settings / Interaction Editor

Player enters screen (before fadein) / Run script

   if (GetGraphicalVariable("globalGateopen") == 0)  // Gate is closed (I use a global variable since I need this state later in the game)
      {
         if (character[EGO].y <= 160)                        // Character is NORTH of the fence
            {
              RemoveWalkableArea(2);                       // make front area unwalkable
              RemoveWalkableArea(3);                       // make middle area unwalkable (which is between the coords 160 and 180)
            }
         if (character[EGO].y >= 180)                        // Character is SOUTH of the fence
            {
              RemoveWalkableArea(1);                       // make back area unwalkable
              RemoveWalkableArea(3);                       // make middle area unwalkable
            }
      }

Since I can change the state of the gate several times while in the same room and therefore change the state of the walkable areas as well, I have to manage that with every interaction with the gate. Is the gate closed and the gate sprite is visible, I can use the object "closed-gate" to interact with. For the gate open state, I define a hotspot on the open gate shown on the background image to interact with. And here are the scripts for each:

Room Editor / Objects / Interaction... Button

Interact object

   Run script

   if (character[EGO].y <= 160)                        // Character is NORTH of the fence
      {
        character[EGO].Walk(170, 160,eBlock);  // walk to the gate (coords depend where you have your gate)
        RestoreWalkableArea(2);                       // make front area walkable
      }
   if (character[EGO].y >= 180)                        // Character is SOUTH of the fence
      {
        character[EGO].Walk(170, 180,eBlock);  // walk to the gate
        RestoreWalkableArea(1);                       // make back area walkable
      }
   RestoreWalkableArea(3);                           // make middle area walkable
   object[0].Visible = false;                            // let gate disappear

   Game - Set variable value (globalGateopen, 1)


Room Editor / Areas / Hotspots / Interaction... Button

Interact hotspot

   Run script

   if (character[EGO].y <= 160)                        // Character is NORTH of the fence
      {
        character[EGO].Walk(170, 160,eBlock);  // walk to the gate
        RemoveWalkableArea(2);                       // make front area unwalkable
      }
   if (character[EGO].y >= 180)                        // Character is SOUTH of the fence
      {
        character[EGO].Walk(170, 180,eBlock);  // walk to the gate
        RemoveWalkableArea(1);                       // make back area unwalkable
      }
   RemoveWalkableArea(3);                           // make middle area unwalkable
   object[0].Visible = true;                             // let gate appear

   Game - Set variable value (globalGateopen, 0)

Thats it!

Thanks!
coming soon (or later, sorry!)

SMF spam blocked by CleanTalk