mirror of
https://github.com/cyberarm/i-mic-rts.git
synced 2025-12-15 15:52:34 +00:00
Improved pathing debug draw
This commit is contained in:
@@ -96,7 +96,10 @@ class IMICRTS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update
|
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
|
if @movement
|
||||||
follow_path
|
follow_path
|
||||||
@@ -113,7 +116,7 @@ class IMICRTS
|
|||||||
|
|
||||||
def follow_path
|
def follow_path
|
||||||
if @pathfinder && node = @pathfinder.path_current_node
|
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
|
@position -= (@position.xy - node.tile.position.xy).normalized * @speed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -130,21 +133,23 @@ class IMICRTS
|
|||||||
def draw_gizmos
|
def draw_gizmos
|
||||||
Gosu.draw_rect(@position.x - @radius, @position.y - (@radius + 2), @radius * 2, 2, Gosu::Color::GREEN, ZOrder::ENTITY_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(
|
Gosu.draw_line(
|
||||||
@position.x, @position.y, Gosu::Color::RED,
|
@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
|
ZOrder::ENTITY_GIZMOS
|
||||||
)
|
)
|
||||||
|
|
||||||
@pathfinder.path.each_with_index do |node, i|
|
node = @pathfinder.path_current_node
|
||||||
next_node = @pathfinder.path.dig(i + 1)
|
@pathfinder.path[@pathfinder.path_current_node_index..@pathfinder.path.size - 1].each do |next_node|
|
||||||
if next_node
|
if node
|
||||||
Gosu.draw_line(
|
Gosu.draw_line(
|
||||||
node.tile.position.x, node.tile.position.y, Gosu::Color::RED,
|
node.tile.position.x, node.tile.position.y, Gosu::Color::RED,
|
||||||
next_node.tile.position.x, next_node.tile.position.y, Gosu::Color::RED,
|
next_node.tile.position.x, next_node.tile.position.y, Gosu::Color::RED,
|
||||||
ZOrder::ENTITY_GIZMOS
|
ZOrder::ENTITY_GIZMOS
|
||||||
)
|
)
|
||||||
|
|
||||||
|
node = next_node
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -74,13 +74,17 @@ class IMICRTS
|
|||||||
@path[@path_current_node]
|
@path[@path_current_node]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def path_current_node_index
|
||||||
|
@path_current_node
|
||||||
|
end
|
||||||
|
|
||||||
def path_next_node
|
def path_next_node
|
||||||
@path_current_node += 1
|
@path_current_node += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def at_current_path_node?(position)
|
def at_current_path_node?(entity)
|
||||||
if node = path_current_node
|
if node = path_current_node
|
||||||
position.distance(node.tile.position) < @map.tile_size / 2
|
entity.position.distance(node.tile.position) <= @entity.radius
|
||||||
else
|
else
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user