mirror of
https://github.com/cyberarm/i-mic-rts.git
synced 2025-12-16 00:02:33 +00:00
Added spawner and waypoint components, added building_set_waypoint order, particle emitters can now toggle their emission, buildings can now build and spawn units, buildings now dynamically emit smoke when working and no longer when building, added player2 to default game for testing.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
class IMICRTS
|
||||
class BuildQueue < Component
|
||||
attr_reader :queue
|
||||
|
||||
Item = Struct.new(:entity, :progress)
|
||||
def setup
|
||||
@queue = []
|
||||
|
||||
@@ -3,11 +3,16 @@ class IMICRTS
|
||||
attr_accessor :pathfinder
|
||||
|
||||
def update
|
||||
if pathfinder && pathfinder.path_current_node
|
||||
rotate_towards(pathfinder.path_current_node.tile.position + @parent.director.map.tile_size / 2)
|
||||
end
|
||||
if @parent.movement == :ground
|
||||
if pathfinder && pathfinder.path_current_node
|
||||
rotate_towards(pathfinder.path_current_node.tile.position + @parent.director.map.tile_size / 2)
|
||||
end
|
||||
|
||||
follow_path
|
||||
follow_path
|
||||
else
|
||||
rotate_towards(@parent.target)
|
||||
@parent.position -= (@parent.position.xy - @parent.target.xy).normalized * @parent.speed
|
||||
end
|
||||
end
|
||||
|
||||
def rotate_towards(vector)
|
||||
|
||||
23
lib/components/spawner.rb
Normal file
23
lib/components/spawner.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
class IMICRTS
|
||||
class Spawner < Component
|
||||
def tick(tick_id)
|
||||
# TODO: Ensure that a build order is created before working on entity
|
||||
|
||||
item = @parent.component(:build_queue).queue.first
|
||||
|
||||
if item
|
||||
item.progress += 1
|
||||
|
||||
if item.progress >= 100 # TODO: Define work units required for construction
|
||||
@parent.component(:build_queue).queue.shift
|
||||
|
||||
spawn_point = @parent.position.clone
|
||||
spawn_point.y += 96 # TODO: Use one of entity's reserved tiles for spawning
|
||||
|
||||
ent = @parent.director.spawn_entity(player_id: @parent.player.id, name: item.entity.name, position: spawn_point)
|
||||
ent.target = @parent.component(:waypoint).waypoint if @parent.component(:waypoint)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
27
lib/components/waypoint.rb
Normal file
27
lib/components/waypoint.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
class IMICRTS
|
||||
class Waypoint < Component
|
||||
def setup
|
||||
@waypoint = @parent.position.clone
|
||||
@waypoint.y += @parent.director.map.tile_size
|
||||
end
|
||||
|
||||
def set(vector)
|
||||
@waypoint = vector
|
||||
end
|
||||
|
||||
def waypoint
|
||||
@waypoint.clone
|
||||
end
|
||||
|
||||
def draw
|
||||
return unless @parent.player.selected_entities.include?(@parent)
|
||||
|
||||
Gosu.draw_line(
|
||||
@parent.position.x, @parent.position.y, @parent.player.color,
|
||||
@waypoint.x, @waypoint.y, @parent.player.color, ZOrder::ENTITY_GIZMOS
|
||||
)
|
||||
|
||||
Gosu.draw_circle(@waypoint.x, @waypoint.y, 4, 9, @parent.player.color, ZOrder::ENTITY_GIZMOS)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user