Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Meistari F on Sun 28/10/2007 15:27:18

Title: Getting very close to object/hotspot.
Post by: Meistari F on Sun 28/10/2007 15:27:18
I'm still beginner here but I'm getting very good on this, but I need a code to do this thing, but I want the player reach to the door and open it only when he is standing very near it. And if the player is not standing on the region or near the door or the object, I want a mesage display then "You are not close enough to the hotspot/object". I just want to know what code do I use for this please.
Title: Re: Getting very close to object/hotspot.
Post by: .M.M. on Sun 28/10/2007 16:15:41
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=32759.0
I hope this can help you.
Title: Re: Getting very close to object/hotspot.
Post by: Khris on Sun 28/10/2007 16:23:05
You can do it using regions.
Region.GetAtRoomXY(player.x, player.y)
returns the region the player is standing on (or region[0] if there's none).
So in the interact door-script or whatever you're using, test for the correct region, otherwise display the message.

Another method is to determine the distance from the object/hotspot.

The distance between x1,y1 and x2,y2 is calculated so:
int Distance(int x1, int y1, int x2, int y2) {
  x1=x1-x2; x1=x1*x1;
  y1=y1-y2; y1=y1*y1;
  return FloatToInt(Maths.Sqrt(IntToFloat(x1)+IntToFloat(y1)));
}

Use another function to calculate the distance from the Player:
int DistancePl(int x, int y) {
  return Distance(player.x, player.y, x, y);
}


Example:
  // interact with object table
  if (DistancePl(oTable.x, oTable.y)>30) Display("You are too far away from the table.");
  else {
    ...
  }
Title: Re: Getting very close to object/hotspot.
Post by: Dualnames on Tue 30/10/2007 08:42:49
I'm sure KhrisMUC has found a solution. but do tell if you want more help on that.
Title: Re: Getting very close to object/hotspot.
Post by: Meistari F on Tue 06/11/2007 23:30:48
Well my character is on second floor and I just wanted to know what the code I have to use when I touch the door wich is on 1 floor and display. "You need to get closer". But the elevator door are not suppose to open until I get close to the elevator door on the first floor.