[SOLVED]Detecting if any character/object occupies an area

Started by Jakey, Sun 20/05/2012 19:00:54

Previous topic - Next topic

Jakey

Hello!

I just started work on a top-down rpg, "pokemon" style kind of game. I've already implemented some grid-based movement for the player and NPCs. I have a function checking if the grid-space a character plans to walk too is walkable or not, but it does not handle the case where another character/object is occupying the space (in which the function should also return false).

My question: Is there a nice way to check if a pixel is occupied by ANY character or object?

Right now my only strategy is to loop through all characters/objects and check if their coordinates lye within the grid space.

Thanks for assisting a newbie :)

monkey0506

You should be able to use Character.GetAtScreenXY and Object.GetAtScreenXY, yes? Also check out GetLocationType. I'd actually suggest just doing:

Code: ags
LocationType type = GetLocationType(x, y); // supply coordinates for grid-point, say in the middle of that space?
if ((type == eLocationCharacter) || (type == eLocationObject)) isWalkable[gridSpaceID] = false; // however you're handling this, the space is blocked and can't be walked to


If you need the specific Character/Object that's when you'd use the GetAtScreenXY functions. ;)

Grid-based movement is pretty cool by the way, and not the simplest of tasks, so props on getting that working.

Jakey

Thanks, that seems just like the function I was looking for.

I was aware of GetAtScreenXY, but GetLocationType is perfect for the job :D

Thanks for help while I still get used to the available functions :)

Khris

Actually, I think your original solution is better, because if you hit a transparent pixel, AGS will miss that the grid cell is blocked.
Are you not storing grid coordinates for each character anyway?

Jakey

Quote from: Khris on Sun 20/05/2012 20:11:31
Actually, I think your original solution is better, because if you hit a transparent pixel, AGS will miss that the grid cell is blocked.
Are you not storing grid coordinates for each character anyway?

Hmmm...But in my case I can't imagine having a character or object completely transparent. My function IsGridWalkable checks all pixels inside one grid space, so if any bit of a character or object is there it won't allow movement. I'm not storing the coordinates for the characters as I haven't needed it thus far, but  maybe I will in the future.

SMF spam blocked by CleanTalk