The post Isometric Coordinate Algorithms appeared first on ATZ OK.
]]>def GetScreenPositionForTile(self, map_pos, view, origin, offset, delta=None): if self.projection == Layer.Projections.BirdsEye: screen_x = origin[0] + map_pos[0] * self.tile_width screen_y = origin[1] + map_pos[1] * self.tile_height if delta is not None: screen_x += delta[0] screen_y += delta[1] elif self.projection == Layer.Projections.Isometric: map_pos = (map_pos[0] - offset[0] / self.scale, map_pos[1] - offset[1] / self.scale) screen_x = origin[0] - (map_pos[1] * self.tile_width / 2) + (map_pos[0] * self.tile_width / 2) - (self.tile_width / 2) screen_y = origin[1] + (map_pos[1] * self.tile_height / 2) + (map_pos[0] * self.tile_height / 2) if delta is not None: iso_delta_x = (delta[0] - delta[1]) / 2 * self.tile_aspect iso_delta_y = (delta[1] / 2) + (delta[0] / 2) screen_x += iso_delta_x screen_y += iso_delta_y return screen_x, screen_y
def GetTileAtScreenPosition(self, screen_pos, view, offset): origin_x, origin_y = self.GetOrigin(view) map_x_screen = screen_pos[0] - origin_x map_y_screen = screen_pos[1] - origin_y if self.projection == Layer.Projections.BirdsEye: map_x = map_x_screen / self.tile_width map_y = map_y_screen / self.tile_height map_delta_x = map_x_screen % self.tile_width map_delta_y = map_y_screen % self.tile_height elif self.projection == Layer.Projections.Isometric: map_x_raw = map_y_screen + int(map_x_screen / self.tile_aspect) map_y_raw = map_y_screen - int(map_x_screen / self.tile_aspect) map_x = map_x_raw / self.tile_height map_y = map_y_raw / self.tile_height map_delta_x = map_x_raw % self.tile_height map_delta_y = map_y_raw % self.tile_height map_x += offset[0] / self.scale map_y += offset[1] / self.scale return map_x, map_y, map_delta_x, map_delta_y
I could comment the code better of course, but I think it’s actually pretty straightforward and self-explanatory.
Full code: http://ohshitzombies.com/PallidumZ/trunk/game/board/Layers.py
The post Isometric Coordinate Algorithms appeared first on ATZ OK.
]]>The post Pathfinding algorithms in Demon Keeper appeared first on ATZ OK.
]]>I found a great A* tutorial, and some great additional information, which helped me get started, but it wasn’t quite what I needed. The first thing I did was to split out the core logic into a function, and create two functions to access it for either a targeted A* route finder, or a Dijkstra search of multiple potential targets. The latter ended up being more heavily used for actions like finding the closest nearby hostile to attack, whereas the A* function is then used to maintain a route once the target is acquired.
What still remains insufficient however, is a node’s binary state of being either a pass or block in pathing. This created two problems: actors immediately in the way of the moving sprite would block its progress flat, and targetable features with no pathing data would return as unreachable. The ultimate solution to this was to pass in three separate path arrays: the board, the features, and the actors.
These three boards may then be analyzed in different ways, depending on where in the path you are. The actor board may be ignored entirely in all but the first move (since that’s the only one in which you can count on it being a factor), or weighted in a node’s F-value, based on distance (i.e. an actor blocking a node will have less value the further it is away from origin). The feature board will be used for the path along the way, but ignored at the final destination point, allowing for blocking features to be targeted, but still routed around along the way.
The post Pathfinding algorithms in Demon Keeper appeared first on ATZ OK.
]]>