Author Topic: [SOLVED]Detecting if any character/object occupies an area  (Read 295 times)  Share 

Jakey

  • Aspiring to finish my first game.
    • I can help with AGS tutoring
    •  
    • I can help with play testing
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
    • I can help with voice acting
    •  
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 :)
« Last Edit: 21 May 2012, 14:35 by Jakey »

monkey_05_06

  • AGS Project Admins
  • Has left the building.
Re: Detecting if any character/object occupies an area
« Reply #1 on: 20 May 2012, 19:12 »
You should be able to use Character.GetAtScreenXY and Object.GetAtScreenXY, yes? Also check out GetLocationType. I'd actually suggest just doing:

Code: Adventure Game Studio
  1. LocationType type = GetLocationType(x, y); // supply coordinates for grid-point, say in the middle of that space?
  2. 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.
Let's be honest. Most people suck at coding. I suck at coding, but at least my code is readable. To Hell with anyone too lazy to maintain consistent formatting in their code. I could deal with bad interfaces and structure if I could even read your horrible code. And that's putting it nicely. -monkey

Jakey

  • Aspiring to finish my first game.
    • I can help with AGS tutoring
    •  
    • I can help with play testing
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
    • I can help with voice acting
    •  
Re: Detecting if any character/object occupies an area
« Reply #2 on: 20 May 2012, 19:50 »
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

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: Detecting if any character/object occupies an area
« Reply #3 on: 20 May 2012, 20:11 »
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?
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

Jakey

  • Aspiring to finish my first game.
    • I can help with AGS tutoring
    •  
    • I can help with play testing
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
    • I can help with voice acting
    •  
Re: Detecting if any character/object occupies an area
« Reply #4 on: 20 May 2012, 20:17 »
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.