Get monster position and area around him.
-
Emera Nova
- Posts: 146
- Joined: Wed Jun 11, 2014 1:31 am
Get monster position and area around him.
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.
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.
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.