Trouble making objects that change visually

Started by MegzHeartcho, Wed 11/03/2009 20:56:08

Previous topic - Next topic

MegzHeartcho

In my game, I want to make certain objects (ie. a safe) change visually depending on certain interacts with it. Here's an example of what I want to happen with the safe:

When the player enters the room, the safe is closed.
When the player interacts with the safe, it stays closes till they have the Password Sheet in their inventory.
When the player get the Password Sheet in their inventory and interacts with the safe, the safe opens and reveals the Elevator Key.
When the player clicks on the open safe, the key disappears and reappears in the player's inventory.
The safe remains empty for the rest of the game.

That's basically what I want to do but I'm not sure of how to go about it. Do I make multiple views of the safe? Is there a certain type of script I should use?

Any help or advice would be greatly appreciated.

Khris

You'll want to draw the safe without its door as part of your background, then add the closed safe door as room object.
Add the key as another room object.
To achieve that the door is displayed above the key (obscuring it) while both objects appear behind the player, you need to set the objects' baselines.
Set the safe door's baseline to a y coord near the lower edge (which should be above the walkable area), then the key's baseline to a y coord a bit further up.

Now you can deal with everything seperately:
To make the door change between being open and closed, simply change the safe door's graphic.
The arguably best way to this is to use two sprites composed like this:

Say the imported sprites end up with numbers 11 & 12:
Code: ags
 // interact with safe
  if (oSafedoor.Graphic == 12) {
    Display("You close the safe.");
    oSafedoor.Graphic == 11;
  }
  else Display("You tug at the door but it won't move an inch.");


 // use inv on safe
  if (player.ActiveInventory == iPasswordsheet) {
    if (oSafedoor.Graphic == 11) {
      Display("You pull out the sheet and enter the combo. The safe opens with a click.");
      oSafedoor.Graphic = 12;
    }
    else Display("The door is already open.");
  }
  else Display("That won't work.");


The key:
Code: ags
  // interact with / pick up key
  oKey.Visible = false;
  player.AddInventory(iKey);


Note that the first 300 rooms safe their state, so the door will remain open and the key gone until you say otherwise.

MegzHeartcho

Quote from: KhrisMUC on Wed 11/03/2009 22:03:00
You'll want to draw the safe without its door as part of your background, then add the closed safe door as room object.
Add the key as another room object.
To achieve that the door is displayed above the key (obscuring it) while both objects appear behind the player, you need to set the objects' baselines.
Set the safe door's baseline to a y coord near the lower edge (which should be above the walkable area), then the key's baseline to a y coord a bit further up.

Now you can deal with everything seperately:
To make the door change between being open and closed, simply change the safe door's graphic.
The arguably best way to this is to use two sprites composed like this:

Say the imported sprites end up with numbers 11 & 12:
Code: ags
 // interact with safe
  if (oSafedoor.Graphic == 12) {
    Display("You close the safe.");
    oSafedoor.Graphic == 11;
  }
  else Display("You tug at the door but it won't move an inch.");


 // use inv on safe
  if (player.ActiveInventory == iPasswordsheet) {
    if (oSafedoor.Graphic == 11) {
      Display("You pull out the sheet and enter the combo. The safe opens with a click.");
      oSafedoor.Graphic = 12;
    }
    else Display("The door is already open.");
  }
  else Display("That won't work.");


The key:
Code: ags
  // interact with / pick up key
  oKey.Visible = false;
  player.AddInventory(iKey);


Note that the first 300 rooms safe their state, so the door will remain open and the key gone until you say otherwise.

Thanks! Though, while I'm still curious, is there a way to have certain actions happen without making certain items in your inventory the active item?

For instance, say the player has collected the elevator key and instead of clicking it in their inventory every time they want to use the elevator, they just have to walk onto the elevator and be sent to the next room. Simply put: If the player has the elevator key in their inventory, the elevator will send them to the next room without having to use the key on it directly.

Is that possible?

Jakerpot

you can use a real password (enter correct numbers or/and letters) to open the safe, use this code;
Code: ags


function room_RepExec()
{

String input=Game.InputBox("Press Ok to go back.");
if (input=="xxx"){                       /// Change the xxx for the correct password
  /// Put here what you want to happen if the password is right
}

else Display("Wrong password.");
         /// Put here what you want to happen if the password is wrong
}
}



;)



Khris

Quote from: MegzHeartcho on Thu 12/03/2009 00:03:04
Thanks! Though, while I'm still curious, is there a way to have certain actions happen without making certain items in your inventory the active item?
Yes, you can check if the player has the item in their possession:
Code: ags
 // walk onto elevator region
  if (player.HasInventory(iKey)) {
    Display("Using the key, you activate the elevator.");
    // animation: doors close
    player.ChangeRoom(2);
  }
  else {
    Display("The elevator needs a key to work.");
    player.Walk(250, 135);   // optional: walk back off the region
  }

MegzHeartcho

Quote from: KhrisMUC on Thu 12/03/2009 10:01:05
Quote from: MegzHeartcho on Thu 12/03/2009 00:03:04
Thanks! Though, while I'm still curious, is there a way to have certain actions happen without making certain items in your inventory the active item?
Yes, you can check if the player has the item in their possession:
Code: ags
 // walk onto elevator region
  if (player.HasInventory(iKey)) {
    Display("Using the key, you activate the elevator.");
    // animation: doors close
    player.ChangeRoom(2);
  }
  else {
    Display("The elevator needs a key to work.");
    player.Walk(250, 135);   // optional: walk back off the region
  }


Awesome, thank you. :3

SMF spam blocked by CleanTalk