Can I make Hotspot.GetAtScreenXY(x, (between y1 and y2)) == hHotspot1? [SOLVED]

Started by iamlowlikeyou, Mon 24/01/2011 19:26:12

Previous topic - Next topic

iamlowlikeyou

Like the headline says;
is it possible to determine whether something is in a location BETWEEN two coordinates, instead of AT one specific coordinate?
I somehow think it should be fairly simple, but I can't quite figure it out...

Khris

The syntax in the headline doesn't make sense.

I'm not sure if you want to look what's in an area(1) or if you want to check if a specific thing is in an area(2). (Do you know what "something" is or are you trying to find out?)

1)
Since you are testing multiple coordinates, there can obviously be multiple hotspots, objects and characters.
You'd need to specify whether you want the e.g. first hotspot, going from x,y1 to x,y2 or the character with the lowest ID, or the object with the greatest y coordinate. In theory you could put all found objects in an array and process that further.

2)
Alternatively, if you actually want to ask how to determine if a specific object currently is within certain coordinates, all you need to do is determine a center point and calculate its distance from the line x,y1 to x,y2.

Please try to explain better what you want to do. Try explaining it as a designer who doesn't know a hotspot from a variable.

iamlowlikeyou

Oh sorry, I wrote rubbish in the headline, I made it right now (I think).

So what I meant was:

Hotspot.GetAtScreenXY(x, (between y1 and y2)) == hHotspot1

The thing is, how to make it decide whether the y coordinate for hHotspot1 is BETWEEN y1 and y2, instead of at EITHER y1 or y2 (or another y-coordinate). Is that possible to implement in GetAtScreenXY, or will I have to do it some other way?

Khris

A Hotspot doesn't have a y coordinate since it's an area of points.

Do you mean: does hHotspot1 occupy all points on the line from x,y1 to x,y2 or
does it occupy at least one?


iamlowlikeyou

At least one.

That is; is some part at all of hHotspot1 between y1 and y2.

Khris

This should work:
Code: ags
bool IsInYRange(this Hotspot*, int x, int y1, int y2) {
  if (y2 < y1) {
    int swap = y1;
    y1 = y2;
    y2 = swap;
  }
  bool found;
  int i = y1;
  while (i <= y2) {
    if (Hotspot.GetAtScreenXY(x, i) == this) {
      found = true;
      i = y2+1; // exit loop
    }
    i++;
  }
  return found;
}


Usage:
  if (hHotspot1.IsInYRange(20, 140, 160)) ...


Khris

You're welcome, note that this isn't exclusive, i.e. using one set of coordinates, it can be true for several hotspots.

SMF spam blocked by CleanTalk