Crude path following implemented

This commit is contained in:
2019-10-25 11:43:07 -05:00
parent 8d71070893
commit 9fcb7f3d6e
3 changed files with 47 additions and 18 deletions

View File

@@ -25,6 +25,7 @@ class IMICRTS
@position = position
@angle = angle
@director = director
@speed = 0.5
@radius = 32 / 2
@target = nil
@@ -41,6 +42,8 @@ class IMICRTS
@goal_color = Gosu::Color.argb(175, 25, 200, 25)
@target_color = Gosu::Color.argb(175, 200, 25, 25)
@orders = []
end
def serialize
@@ -96,6 +99,7 @@ class IMICRTS
rotate_towards(@target) if @target && @movement
if @movement
follow_path
end
end
@@ -107,6 +111,13 @@ class IMICRTS
@on_tick = block
end
def follow_path
if @pathfinder && node = @pathfinder.path_current_node
@pathfinder.path_next_node if @pathfinder.at_current_path_node?(@position)
@position -= (@position.xy - node.tile.position.xy).normalized * @speed
end
end
def selected_draw
draw_radius
draw_gizmos