GetWalkbehindAt?

Started by Calin Leafshade, Fri 18/02/2011 04:07:03

Previous topic - Next topic

Calin Leafshade

Is there a GetWalkBehindAtRoom function? Or something similar.

Can't find anything in the manual but it seems like an odd thing to leave out.

Hernald

I would be interested in a work-around for this as well.

Khris

I'd put the current Walkbehind map in a sprite and use GetPixel.
Not terribly elegant but seems to be the only way.

monkey0506

#3
You could use some script to determine whether there was a walkbehind, but there's not currently a way to check which:

Code: ags
bool IsAnyWalkbehindAtScreenXY(int x, int y)
{
  int px = player.x;
  int py = player.y;
  int pb = player.Baseline;
  bool pi = player.IgnoreWalkbehinds;
  player.x = x + GetViewportX();
  player.y = y + GetViewportY();
  player.Baseline = 1;
  player.IgnoreWalkbehinds = false;
  bool gv[] = new bool[Game.GUICount]; // the potential overallocation here is more efficient than constantly reallocating
  GUI *gp[] = new GUI[Game.GUICount];
  int gc = 0;
  bool ov[] = new bool[Room.ObjectCount];
  Object *op[] = new Object[Room.ObjectCount];
  int oc = 0;
  GUI *gat = GUI.GetAtScreenXY(x, y);
  while (gat != null)
  {
    gv[gc] = gat.Visible;
    gp[gc] = gat;
    gc++;
    gat = GUI.GetAtScreenXY(x, y);
  }
  LocationType lt = GetLocationType(x, y);
  while (lt == eLocationObject)
  {
    Object *oat = Object.GetAtScreenXY(x, y);
    ov[oc] = oat.Visible;
    op[oc] = oat;
    oc++;
    oat.Visible = false;
    lt = GetLocationType(x, y);
  }
  int i = 0;
  while ((i < gc) && (i < oc))
  {
    if (i < gc) gp[i].Visible = gv[i];
    if (i < oc) op[i].Visible = ov[i];
    i++;
  }
  player.x = px;
  player.y = py;
  player.Baseline = pb;
  player.IgnoreWalkbehinds = pi;
  return (lt != eLocationCharacter);
}


I haven't actually tested this (:=) but my general line of thinking here is that if the player is actually standing at the specified coordinates with no GUIs or Objects in front of him, and not ignoring walkbehinds, then GetLocationType should be able to tell us whether or not he is behind a walkbehind.

It has some caveats such as only working with screen coordinates (because there's no GetLocationTypeAtRoomXY), and it might explode your game if you try and check it while the player is actually moving...but depending on your purposes this might be sufficient?

Khris' way is probably more elegant than mine, and would actually allow checking IDs instead of just checking existence, but mine was more fun to come up with! :P

Hernald

Thanks for your responses. This seems like the time for me to investigate DrawingSurface functions and properties.  :)

Wyz

If I remember correctly the walkbehind maps are exposed to the plugin API, but again not a very elegant solution. Khis' solution sound like to most elegant so far.
Life is like an adventure without the pixel hunts.

SMF spam blocked by CleanTalk