diff --git a/lib/components/movement.rb b/lib/components/movement.rb index 211f7df..94c79bf 100644 --- a/lib/components/movement.rb +++ b/lib/components/movement.rb @@ -24,7 +24,7 @@ class IMICRTS def follow_path if @pathfinder && node = @pathfinder.path_current_node @pathfinder.path_next_node if @pathfinder.at_current_path_node?(@parent) - @parent.position -= (@parent.position.xy - node.tile.position.xy).normalized * @parent.speed + @parent.position -= (@parent.position.xy - (node.tile.position + @parent.director.map.tile_size / 2).xy).normalized * @parent.speed end end end diff --git a/lib/entity.rb b/lib/entity.rb index 6ca604a..8bd785f 100644 --- a/lib/entity.rb +++ b/lib/entity.rb @@ -132,7 +132,7 @@ class IMICRTS def update if component(:movement) if component(:movement).pathfinder && component(:movement).pathfinder.path_current_node - component(:movement).rotate_towards(component(:movement).pathfinder.path_current_node.tile.position) + component(:movement).rotate_towards(component(:movement).pathfinder.path_current_node.tile.position + @director.map.tile_size / 2) end component(:movement).follow_path @@ -163,21 +163,25 @@ class IMICRTS end def draw_gizmos + # healthbar Gosu.draw_rect(@position.x - @radius, @position.y - (@radius + 2), @radius * 2, 2, Gosu::Color::GREEN, ZOrder::ENTITY_GIZMOS) if Setting.enabled?(:debug_pathfinding) && component(:movement) && component(:movement).pathfinder && component(:movement).pathfinder.path_current_node + current_node = component(:movement).pathfinder.path_current_node.tile.position + @director.map.tile_size / 2 Gosu.draw_line( @position.x, @position.y, Gosu::Color::RED, - component(:movement).pathfinder.path_current_node.tile.position.x, component(:movement).pathfinder.path_current_node.tile.position.y, Gosu::Color::RED, + current_node.x, current_node.y, Gosu::Color::RED, ZOrder::ENTITY_GIZMOS ) - node = component(:movement).pathfinder.path_current_node + node = component(:movement).pathfinder.path_current_node.tile.position + @director.map.tile_size / 2 component(:movement).pathfinder.path[component(:movement).pathfinder.path_current_node_index..component(:movement).pathfinder.path.size - 1].each do |next_node| if node + next_node = next_node.tile.position + @director.map.tile_size / 2 + Gosu.draw_line( - node.tile.position.x, node.tile.position.y, Gosu::Color::RED, - next_node.tile.position.x, next_node.tile.position.y, Gosu::Color::RED, + node.x, node.y, Gosu::Color::RED, + next_node.x, next_node.y, Gosu::Color::RED, ZOrder::ENTITY_GIZMOS ) diff --git a/lib/pathfinding/base_pathfinder.rb b/lib/pathfinding/base_pathfinder.rb index 284e008..1bbaf42 100644 --- a/lib/pathfinding/base_pathfinder.rb +++ b/lib/pathfinding/base_pathfinder.rb @@ -84,7 +84,7 @@ class IMICRTS def at_current_path_node?(entity) if node = path_current_node - entity.position.distance(node.tile.position) <= @entity.radius + entity.position.distance((node.tile.position + @map.tile_size / 2).xy) <= @entity.radius else true end