Improved pathing debug draw

This commit is contained in:
2019-10-25 13:56:54 -05:00
parent 9fcb7f3d6e
commit 202331474b
2 changed files with 18 additions and 9 deletions

View File

@@ -96,7 +96,10 @@ class IMICRTS
end
def update
rotate_towards(@target) if @target && @movement
if @movement
# rotate_towards(@target) if @target
rotate_towards(@pathfinder.path_current_node.tile.position) if @pathfinder && @pathfinder.path_current_node
end
if @movement
follow_path
@@ -113,7 +116,7 @@ class IMICRTS
def follow_path
if @pathfinder && node = @pathfinder.path_current_node
@pathfinder.path_next_node if @pathfinder.at_current_path_node?(@position)
@pathfinder.path_next_node if @pathfinder.at_current_path_node?(self)
@position -= (@position.xy - node.tile.position.xy).normalized * @speed
end
end
@@ -130,21 +133,23 @@ class IMICRTS
def draw_gizmos
Gosu.draw_rect(@position.x - @radius, @position.y - (@radius + 2), @radius * 2, 2, Gosu::Color::GREEN, ZOrder::ENTITY_GIZMOS)
if @pathfinder && Setting.enabled?(:debug_pathfinding) && @pathfinder.path.first
if @pathfinder && @pathfinder.path_current_node && Setting.enabled?(:debug_pathfinding) && @pathfinder.path.first
Gosu.draw_line(
@position.x, @position.y, Gosu::Color::RED,
@pathfinder.path.first.tile.position.x, @pathfinder.path.first.tile.position.y, Gosu::Color::RED,
@pathfinder.path_current_node.tile.position.x, @pathfinder.path_current_node.tile.position.y, Gosu::Color::RED,
ZOrder::ENTITY_GIZMOS
)
@pathfinder.path.each_with_index do |node, i|
next_node = @pathfinder.path.dig(i + 1)
if next_node
node = @pathfinder.path_current_node
@pathfinder.path[@pathfinder.path_current_node_index..@pathfinder.path.size - 1].each do |next_node|
if node
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,
ZOrder::ENTITY_GIZMOS
)
node = next_node
end
end
end

View File

@@ -74,13 +74,17 @@ class IMICRTS
@path[@path_current_node]
end
def path_current_node_index
@path_current_node
end
def path_next_node
@path_current_node += 1
end
def at_current_path_node?(position)
def at_current_path_node?(entity)
if node = path_current_node
position.distance(node.tile.position) < @map.tile_size / 2
entity.position.distance(node.tile.position) <= @entity.radius
else
true
end