added on_order handler to entities and components, added visibility map

This commit is contained in:
2021-01-15 17:41:06 -06:00
parent e30d73d4d7
commit 19c5fc8d73
22 changed files with 164 additions and 51 deletions

View File

@@ -17,6 +17,16 @@ class IMICRTS
end
end
def on_order(type, order)
case type
when IMICRTS::Order::MOVE
@parent.target = order.vector
when IMICRTS::Order::STOP
@parent.target = nil
@pathfinder = nil
end
end
def rotate_towards(vector)
angle = Gosu.angle(@parent.position.x, @parent.position.y, vector.x, vector.y)
a = (360.0 + (angle - @parent.angle)) % 360.0
@@ -34,7 +44,7 @@ class IMICRTS
end
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)
@parent.position -= (@parent.position.xy - (node.tile.position + @parent.director.map.tile_size / 2).xy).normalized * @parent.speed
end

View File

@@ -1,5 +1,12 @@
class IMICRTS
class Spawner < Component
attr_accessor :spawnpoint
def setup
@spawnpoint = @parent.position.clone
@spawnpoint.y += 64
end
def tick(tick_id)
item = @parent.component(:build_queue).queue.first
@@ -12,5 +19,15 @@ class IMICRTS
item.completed = true
@parent.director.schedule_order(IMICRTS::Order::BUILD_UNIT_COMPLETE, @parent.player.id, @parent.id)
end
def on_order(type, order)
case type
when IMICRTS::Order::BUILD_UNIT_COMPLETE
item = @parent.component(:build_queue).queue.shift
ent = @parent.director.spawn_entity(player_id: @parent.player.id, name: item.entity.name, position: @spawnpoint)
ent.target = @parent.component(:waypoint).waypoint if @parent.component(:waypoint)
end
end
end
end

View File

@@ -33,6 +33,13 @@ class IMICRTS
end
end
def on_order(type, order)
case type
when IMICRTS::Order::CONSTRUCTION_COMPLETE
data.construction_complete = true
end
end
def construction_complete?
data.construction_progress >= data.construction_goal && data.construction_complete
end

View File

@@ -2,7 +2,7 @@ class IMICRTS
class Waypoint < Component
def setup
@waypoint = @parent.position.clone
@waypoint.y += @parent.director.map.tile_size
@waypoint.y += @parent.director.map.tile_size * 2
@waypoint_color = 0xffffff00
end