Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: mode7 on Wed 27/10/2010 21:18:30

Title: Problem identifing a certain coordinate on screen
Post by: mode7 on Wed 27/10/2010 21:18:30
I'm using a modified version of Bernies very simple platformer script.
Anyway collisions are handled by determining if a certain coordinate lies on a walkable area.
It works fine so far by using routines like this:

if (GetWalkableAreaAt(player.x-GetViewportX(),player.y-128-GetViewportY())==1)  Display ("Collision");

The problem is it doesn't work properly while the screen is moving (e.g. if it is moving up while jumping the "player.y-128-GetViewportY()" stays the same value) leading to wrong results.

I think it originates in the player using room coordinates and the GetWalkableArea using screen coordinates.

I really hope there's a workaround for this because I don't know another way of doing it.
Title: Re: Problem identifing a certain coordinate on screen
Post by: Khris on Wed 27/10/2010 21:43:04
Quote from: mode7 on Wed 27/10/2010 21:18:30I think it originates in the player using room coordinates and the GetWalkableArea using screen coordinates.

Exactly for this reason the code uses GetViewportX/Y() to translate room to screen coordinates.

Without knowing more about your game it's wild guessing.
How wide are the walkable areas? Do they actually have ID 1? How do you know it stays the same value?
Title: Re: Problem identifing a certain coordinate on screen
Post by: mode7 on Wed 27/10/2010 22:34:08
Quote from: Khris on Wed 27/10/2010 21:43:04
Quote from: mode7 on Wed 27/10/2010 21:18:30I think it originates in the player using room coordinates and the GetWalkableArea using screen coordinates.

Exactly for this reason the code uses GetViewportX/Y() to translate room to screen coordinates.

Without knowing more about your game it's wild guessing.
How wide are the walkable areas? Do they actually have ID 1? How do you know it stays the same value?
the game uses some kind of pseudo physics to move the player down until it hits a walkable area. so the walkable area is actually the blocking part. this piece of code is actually stopping the player from moving further up which is not really important because it just checks a certain coordinate while moving up in rep exec.

Anyway when jumping up while scrolling the player is not actually moving if you just look at the screen cos which i need for GetWalkableArea. I know that because I draw GetViewportY-player.y on a gui and the value stays constant while the screen is scrolling this results that the walkable area is detected much higher than it appears on screen.

Ps: yeah ID1 is right
Title: Re: Problem identifing a certain coordinate on screen
Post by: Calin Leafshade on Wed 27/10/2010 22:44:19
what is the -128 part for?

Title: Re: Problem identifing a certain coordinate on screen
Post by: Khris on Thu 28/10/2010 01:29:10
I guess the player sprite's height is 128; this is for a collision check during the player sprite going up.

mode7:
I've done a few tests and it looks like GetWalkableAreaAt() doesn't require screen but actually room coordinates.
The manual mentions screen coordinates, but the command readily accepts coordinates outside the screen's dimensions and reliably returns the walkable area ID even outside the screen.

Looks like all you need to do is remove the GetViewport stuff and you're set.

I guess that at some point the coordinate type was deliberately changed (to match regions) but the change never made it into the manual, too.
Title: Re: Problem identifing a certain coordinate on screen
Post by: mode7 on Thu 28/10/2010 06:09:55
Thanks a lot Khris!!!
This really helps, will try it out when i get home.
Title: Re: Problem identifing a certain coordinate on screen
Post by: mode7 on Thu 28/10/2010 10:14:38
Ok first of all you were right. You can use room coordinates, which really helps with speed and coding

But I'm afraid that the problem still persists.
I changed the script to make a simple ledge detection:

function repeatedly_execute_always() {
if (GetWalkableAreaAt(player.x+30,player.y-128)==1 && GetWalkableAreaAt(player.x+30,player.y-138)==0) Display ("Collision");
}

only works in right direction but its just a test.

Here is an image so that you can imagnine what it looks like:
(http://img818.imageshack.us/img818/6132/problemf.th.png) (http://img818.imageshack.us/i/problemf.png/)

Uploaded with ImageShack.us (http://imageshack.us)