Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Trent R on Tue 11/11/2008 07:58:34

Title: Need to workaround Screen coords, need Room coords instead. [SOLVED]
Post by: Trent R on Tue 11/11/2008 07:58:34
GAAHHH!! I've been working for the last few hours on my overhead battle system. To make movement cleaner, and to be able to detect objects and characters, I wrote the following function. It's not finished, but I'm just worrying about the movement part (ie. Hspot parameter is not used yet)


function ChangeHex (Character* Char, FacingEnum param, Hotspot* Hspot){
  int CFx, CFy;
  if (param==eFaceDL)       {CFx=Char.x-88; CFy=Char.y+50; } //These distances are specific to the grid
  else if (param==eFaceDown){CFx=Char.x;    CFy=Char.y+100;} //High-res coords are used in scripts
  else if (param==eFaceDR)  {CFx=Char.x+88; CFy=Char.y+50; }
  else if (param==eFaceUL)  {CFx=Char.x-88; CFy=Char.y-50; }
  else if (param==eFaceUp)  {CFx=Char.x;    CFy=Char.y-100;}
  else if (param==eFaceUR)  {CFx=Char.x+88; CFy=Char.y-50; }

  //Char.Walk(CFx, CFy, eBlock); //Works fine, but wouldn't allow the checking I wish to implement

  if (Char==player) BattleHot=Hotspot.GetAtScreenXY(player.x, player.y); //BattleHot is to be the hotspot where the player is
  Char.Walk(BattleHot.WalkToX, BattleHot.WalkToY, eBlock, eAnywhere);    //Obviously doesn't work
}


(http://www.freewebs.com/laboheme/Images/Rune/hex_screen2.png)
This image is my map, and each colored hex has a hotspot associated with it. I had hoped that I could find which hotspot is directly in the direction of FacingEnum, and then check whether or not an enemy or object was at that hotspot.

But since this is a vertical scrolling room, GetAtScreenXY screws up if the player is down at all..... Can anyone of you help me to find a workaround to fix this? Or even to scrap my hotspot idea?


~Trent
Title: Re: Need to workaround Screen coords, need Room coords instead.
Post by: Gilbert on Tue 11/11/2008 08:57:50
if (Char==player) BattleHot=Hotspot.GetAtScreenXY(player.x-GetViewportX(), player.y-GetViewportY()); //BattleHot is to be the hotspot where the player is

Of course, if the room won't scroll horizontally you can leave out the GetViewportX() part, but it doesn't hurt having it.
Title: Re: Need to workaround Screen coords, need Room coords instead.
Post by: Trent R on Tue 11/11/2008 19:40:35
This is happenining more and more to me. I work on something for hours, and get driven to the point where I have no idea what to do, and post it on the forums. And then it's something extremely simple.

Thank you Gilbot!


~Trent