Page 1 of 1

Get monster position and area around him.

Posted: Tue Apr 07, 2015 6:02 pm
by Emera Nova
What im looking for is what is needed to check where a monster is and then in the adjacent squares send out a spell so that it damages anything in those tiles.

Re: Get monster position and area around him.

Posted: Wed Apr 08, 2015 5:45 am
by Eburt
There are several ways to do this and I find that the easiest way depends on where you are trying to get the information. E.g., if say you're defining an attack for that monster, or adding a hook to any other component of that monster you can use self.go.x and self.go.y to obtain the x and y positions. Then just add/subtract 1 from each as appropriate to get the adjacent squares. GameObject.getPosition() and GameObject.getWorldPosition() can also be useful, depending on what you are doing.

Note that you probably want some error checking in case the monster is on the edge of the map since trying to create the tile damager (or anything else) outside the map bounds will crash the game. Elevation may also be something you want to consider. Hope this helps.