paths are now in center of tiles instead of at top-left corner

This commit is contained in:
2019-11-28 09:40:59 -06:00
parent 81461778df
commit db5e61e5ea
3 changed files with 11 additions and 7 deletions

View File

@@ -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

View File

@@ -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
)

View File

@@ -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