mirror of
https://github.com/cyberarm/i-mic-rts.git
synced 2025-12-13 06:52:33 +00:00
paths are now in center of tiles instead of at top-left corner
This commit is contained in:
@@ -24,7 +24,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?(@parent)
|
@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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ class IMICRTS
|
|||||||
def update
|
def update
|
||||||
if component(:movement)
|
if component(:movement)
|
||||||
if component(:movement).pathfinder && component(:movement).pathfinder.path_current_node
|
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
|
end
|
||||||
|
|
||||||
component(:movement).follow_path
|
component(:movement).follow_path
|
||||||
@@ -163,21 +163,25 @@ class IMICRTS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def draw_gizmos
|
def draw_gizmos
|
||||||
|
# healthbar
|
||||||
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 Setting.enabled?(:debug_pathfinding) && component(:movement) && component(:movement).pathfinder && component(:movement).pathfinder.path_current_node
|
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(
|
Gosu.draw_line(
|
||||||
@position.x, @position.y, Gosu::Color::RED,
|
@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
|
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|
|
component(:movement).pathfinder.path[component(:movement).pathfinder.path_current_node_index..component(:movement).pathfinder.path.size - 1].each do |next_node|
|
||||||
if node
|
if node
|
||||||
|
next_node = next_node.tile.position + @director.map.tile_size / 2
|
||||||
|
|
||||||
Gosu.draw_line(
|
Gosu.draw_line(
|
||||||
node.tile.position.x, node.tile.position.y, Gosu::Color::RED,
|
node.x, node.y, Gosu::Color::RED,
|
||||||
next_node.tile.position.x, next_node.tile.position.y, Gosu::Color::RED,
|
next_node.x, next_node.y, Gosu::Color::RED,
|
||||||
ZOrder::ENTITY_GIZMOS
|
ZOrder::ENTITY_GIZMOS
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class IMICRTS
|
|||||||
|
|
||||||
def at_current_path_node?(entity)
|
def at_current_path_node?(entity)
|
||||||
if node = path_current_node
|
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
|
else
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user