mirror of
https://github.com/cyberarm/i-mic-rts.git
synced 2025-12-13 06:52:33 +00:00
Added last 2 units, added sidebar actions and build queue components, entities can now have their build actions put on the sidebar
This commit is contained in:
@@ -7,7 +7,7 @@ class IMICRTS
|
||||
end
|
||||
|
||||
def self.inherited(klass)
|
||||
name = klass.to_s.split("::").last.downcase.to_sym
|
||||
name = klass.to_s.split("::").last.gsub(/([^A-Z])([A-Z]+)/,'\1_\2').downcase.to_sym
|
||||
|
||||
if get(name)
|
||||
raise "#{klass.inspect} is already defined!"
|
||||
|
||||
14
lib/components/build_queue.rb
Normal file
14
lib/components/build_queue.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
class IMICRTS
|
||||
class BuildQueue < Component
|
||||
Item = Struct.new(:entity, :progress)
|
||||
def initialize(parent:)
|
||||
@parent = parent
|
||||
|
||||
@queue = []
|
||||
end
|
||||
|
||||
def add(type)
|
||||
@queue << Item.new(Entity.get(type), 0.0)
|
||||
end
|
||||
end
|
||||
end
|
||||
27
lib/components/sidebar_actions.rb
Normal file
27
lib/components/sidebar_actions.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
class IMICRTS
|
||||
class SidebarActions < Component
|
||||
Action = Struct.new(:label, :image, :description, :block)
|
||||
|
||||
attr_reader :actions
|
||||
def initialize(parent:)
|
||||
@parent = parent
|
||||
|
||||
@actions = []
|
||||
end
|
||||
|
||||
def add(action, *args)
|
||||
case action
|
||||
when :add_to_build_queue
|
||||
action = Action.new
|
||||
ent = IMICRTS::Entity.get(args.first)
|
||||
action.label = ent.name.to_s
|
||||
action.description = "Cost: #{ent.cost}\n#{ent.description}"
|
||||
action.block = proc { @parent.component(:build_queue).add(args.first) }
|
||||
|
||||
@actions << action
|
||||
else
|
||||
raise "Unhandled sidebar action: #{action.inspect}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,4 +1,6 @@
|
||||
IMICRTS::Entity.define_entity(:barracks, :building, 400, "Builds and soldiers") do |entity|
|
||||
entity.has(:build_queue)
|
||||
|
||||
entity.radius = 44
|
||||
entity.max_health = 100.0
|
||||
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
IMICRTS::Entity.define_entity(:construction_yard, :building, 2_000, "Provides radar and builds construction workers") do |entity|
|
||||
entity.has(:build_queue)
|
||||
entity.has(:sidebar_actions)
|
||||
entity.component(:sidebar_actions).add(:add_to_build_queue, :construction_worker)
|
||||
|
||||
entity.radius = 40
|
||||
entity.max_health = 100.0
|
||||
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
IMICRTS::Entity.define_entity(:helipad, :building, 1_000, "Builds and rearms helicopters") do |entity|
|
||||
entity.has(:build_queue)
|
||||
entity.has(:sidebar_actions)
|
||||
entity.component(:sidebar_actions).add(:add_to_build_queue, :helicopter)
|
||||
|
||||
entity.radius = 26
|
||||
entity.max_health = 100.0
|
||||
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
IMICRTS::Entity.define_entity(:war_factory, :building, 2_000, "Generates credits") do |entity|
|
||||
IMICRTS::Entity.define_entity(:war_factory, :building, 2_000, "Builds units") do |entity|
|
||||
entity.has(:build_queue)
|
||||
entity.has(:sidebar_actions)
|
||||
entity.component(:sidebar_actions).add(:add_to_build_queue, :jeep)
|
||||
entity.component(:sidebar_actions).add(:add_to_build_queue, :tank)
|
||||
entity.component(:sidebar_actions).add(:add_to_build_queue, :harvester)
|
||||
|
||||
entity.radius = 48
|
||||
entity.max_health = 100.0
|
||||
|
||||
|
||||
14
lib/entities/units/helicopter.rb
Normal file
14
lib/entities/units/helicopter.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
IMICRTS::Entity.define_entity(:helicopter, :unit, 400, "Attacks ground targets") do |entity|
|
||||
entity.has(:movement)
|
||||
|
||||
entity.radius = 14
|
||||
entity.movement = :air
|
||||
entity.max_health = 100.0
|
||||
|
||||
entity.body_image = "vehicles/helicopter/helicopter.png"
|
||||
entity.shell_image = "vehicles/helicopter/helicopter_shell.png"
|
||||
entity.overlay_image = "vehicles/helicopter/helicopter_overlay.png"
|
||||
|
||||
entity.on_tick do
|
||||
end
|
||||
end
|
||||
17
lib/entities/units/jeep.rb
Normal file
17
lib/entities/units/jeep.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
IMICRTS::Entity.define_entity(:jeep, :unit, 400, "Attacks ground targets") do |entity|
|
||||
entity.has(:movement)
|
||||
entity.has(:turret)
|
||||
|
||||
entity.radius = 14
|
||||
entity.movement = :ground
|
||||
entity.max_health = 100.0
|
||||
|
||||
entity.body_image = "vehicles/jeep/jeep.png"
|
||||
entity.shell_image = "vehicles/jeep/tank_shell.png"
|
||||
|
||||
entity.component(:turret).shell_image = "vehicles/jeep/jeep_turret_shell.png"
|
||||
entity.component(:turret).center.y = 0.3125
|
||||
|
||||
entity.on_tick do
|
||||
end
|
||||
end
|
||||
@@ -67,7 +67,7 @@ class IMICRTS
|
||||
if component
|
||||
@components[symbol] = component.new(parent: self)
|
||||
else
|
||||
raise "Unknown component: #{component.inspect}"
|
||||
raise "Unknown component: #{symbol.inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -69,6 +69,17 @@ class IMICRTS
|
||||
@director.schedule_order(Order::SELECTED_UNITS, @player.id, @selected_entities)
|
||||
else
|
||||
pick_entity
|
||||
if ent = @selected_entities.first
|
||||
return unless ent.component(:sidebar_actions)
|
||||
|
||||
@game.sidebar_actions.clear do |stack|
|
||||
ent.component(:sidebar_actions).actions.each do |action|
|
||||
stack.button action.label, tip: action.description do
|
||||
action.block.call if action.block
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@ class IMICRTS
|
||||
class Game < CyberarmEngine::GuiState
|
||||
Overlay = Struct.new(:image, :position, :angle, :alpha)
|
||||
|
||||
attr_reader :sidebar, :overlays
|
||||
attr_reader :sidebar, :sidebar_actions, :overlays
|
||||
def setup
|
||||
window.show_cursor = true
|
||||
@options[:networking_mode] ||= :host
|
||||
@@ -21,8 +21,8 @@ class IMICRTS
|
||||
label "SIDEBAR", text_size: 78, margin_bottom: 20
|
||||
|
||||
flow(width: 1.0) do
|
||||
@buttons = stack(width: 0.9) do
|
||||
@h = button("Harvester", width: 1.0) do
|
||||
@sidebar_actions = stack(width: 0.9) do
|
||||
button("Harvester", width: 1.0) do
|
||||
@player.entities << Entity.new(
|
||||
name: :harvester,
|
||||
director: @director,
|
||||
@@ -32,7 +32,7 @@ class IMICRTS
|
||||
angle: rand(360)
|
||||
)
|
||||
end
|
||||
@c = button("Construction Worker", width: 1.0) do
|
||||
button("Construction Worker", width: 1.0) do
|
||||
@player.entities << Entity.new(
|
||||
name: :construction_worker,
|
||||
director: @director,
|
||||
@@ -42,7 +42,7 @@ class IMICRTS
|
||||
angle: rand(360)
|
||||
)
|
||||
end
|
||||
@t = button("Tank", width: 1.0) do
|
||||
button("Tank", width: 1.0) do
|
||||
@player.entities << Entity.new(
|
||||
name: :tank,
|
||||
director: @director,
|
||||
|
||||
Reference in New Issue
Block a user