Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: thecatamites on Sat 23/01/2010 22:01:23

Title: top-down rpg style button interaction [SOLVED]
Post by: thecatamites on Sat 23/01/2010 22:01:23
Hello,
I'm making a short game in the style of top-down rpgs like Earthbound, etc., and I'm trying to set it up so that pressing the 'Z' key will interact with nearby people and objects. The way I'm doing this is by an on_key_press script that runs ProcessClick(player.x, player.y, eModeInteract) when Z is pressed and by having the NPCs be just part of the backround screen with a hotspot covering an area around them.

I think the problem I'm having has to do with the way the player x and y coordinates are calculated: my approach works okay for some characters at the top of the screen, when approaching them from the south, but for others near the bottom it doesn't work at all when the player is right next to/above them and then suddenly works when the character is a fair difference above them and should technically be outside the hotspot zone.

Basically I was wondering if anyone had any thoughts as to what the problem or solution here might be, or even alternate methods of pulling off the control scheme described above. Thanks!
Title: Re: top-down rpg style button interaction
Post by: tzachs on Sat 23/01/2010 22:21:19
I think that's because the x & y of the player are in room co-ordinates, whereas GetAtScreenXY for hotspot is in screen co-ordinates.

Is your room a scrolling room?

If it is, try running instead of GetAtScreenXY(player.x,player.y) --> GetAtScreenXY(player.x + GetViewportX(), player.y + GetViewportY())
Title: Re: top-down rpg style button interaction
Post by: Khris on Sat 23/01/2010 22:29:43
It's supposed to be
  ProcessClick(player.x - GetViewportX(), player.y - GetViewportY(), eModeInteract);
(To get from room to screen coords, substract the viewport coords.)
Title: Re: top-down rpg style button interaction
Post by: thecatamites on Sat 23/01/2010 22:36:38
Oh, that did it! Thanks, guys!