mirror of
https://github.com/cyberarm/i-mic-rts.git
synced 2025-12-13 06:52:33 +00:00
Added replaced sidebar label buttons with images, added 'radar' (currently static map image)
This commit is contained in:
@@ -15,7 +15,10 @@ class IMICRTS
|
||||
ent = IMICRTS::Entity.get(data[:entity])
|
||||
raise "Failed to find entity: #{data[:entity].inspect}" unless ent
|
||||
|
||||
entity = Entity.new(name: ent.name, player: @parent, id: 0, position: CyberarmEngine::Vector.new, angle: 0, director: nil, proto_entity: true)
|
||||
|
||||
action.label = ent.name.to_s.split("_").map{ |s| s.capitalize }.join(" ")
|
||||
action.image = entity.render
|
||||
action.description = "#{action.label}\nCost: #{ent.cost}\n#{ent.description}"
|
||||
action.block = proc do
|
||||
@parent.director.schedule_order(IMICRTS::Order::BUILD_UNIT, @parent.player.id, @parent.id, data[:entity])
|
||||
@@ -25,7 +28,10 @@ class IMICRTS
|
||||
ent = IMICRTS::Entity.get(data[:entity])
|
||||
raise "Failed to find entity: #{data[:entity].inspect}" unless ent
|
||||
|
||||
entity = Entity.new(name: ent.name, player: @parent, id: 0, position: CyberarmEngine::Vector.new, angle: 0, director: nil, proto_entity: true)
|
||||
|
||||
action.label = ent.name.to_s.split("_").map { |s| s.capitalize }.join(" ")
|
||||
action.image = entity.render
|
||||
action.description = "#{action.label}\nCost: #{ent.cost}\n#{ent.description}"
|
||||
action.block = proc { @parent.director.game.set_tool(data[:tool], data) }
|
||||
|
||||
|
||||
@@ -6,11 +6,13 @@ tiles = [
|
||||
[false, :path, :path, :path, false],
|
||||
]
|
||||
|
||||
IMICRTS::Entity.define_entity(:barracks, :building, 400, 40, "Builds and soldiers", tiles) do |entity|
|
||||
entity.has(:building)
|
||||
entity.has(:waypoint)
|
||||
entity.has(:spawner)
|
||||
entity.has(:build_queue)
|
||||
IMICRTS::Entity.define_entity(:barracks, :building, 400, 40, "Builds and heals soldiers", tiles) do |entity|
|
||||
unless entity.proto_entity
|
||||
entity.has(:building)
|
||||
entity.has(:waypoint)
|
||||
entity.has(:spawner)
|
||||
entity.has(:build_queue)
|
||||
end
|
||||
|
||||
entity.radius = 44
|
||||
entity.max_health = 100.0
|
||||
|
||||
@@ -7,12 +7,14 @@ tiles = [
|
||||
]
|
||||
|
||||
IMICRTS::Entity.define_entity(:construction_yard, :building, 2_000, 310, "Provides radar and builds construction workers", tiles) do |entity|
|
||||
entity.has(:building)
|
||||
entity.has(:waypoint)
|
||||
entity.has(:spawner)
|
||||
entity.has(:build_queue)
|
||||
entity.has(:sidebar_actions)
|
||||
entity.component(:sidebar_actions).add(:add_to_build_queue, { entity: :construction_worker })
|
||||
unless entity.proto_entity
|
||||
entity.has(:building)
|
||||
entity.has(:waypoint)
|
||||
entity.has(:spawner)
|
||||
entity.has(:build_queue)
|
||||
entity.has(:sidebar_actions)
|
||||
entity.component(:sidebar_actions).add(:add_to_build_queue, { entity: :construction_worker })
|
||||
end
|
||||
|
||||
entity.radius = 40
|
||||
entity.max_health = 100.0
|
||||
|
||||
@@ -6,13 +6,15 @@ tiles = [
|
||||
[false, false, false, false, false],
|
||||
]
|
||||
|
||||
IMICRTS::Entity.define_entity(:helipad, :building, 1_000, 100, "Builds and rearms helicopters", tiles) do |entity|
|
||||
entity.has(:building)
|
||||
entity.has(:waypoint)
|
||||
entity.has(:spawner)
|
||||
entity.has(:build_queue)
|
||||
entity.has(:sidebar_actions)
|
||||
entity.component(:sidebar_actions).add(:add_to_build_queue, { entity: :helicopter })
|
||||
IMICRTS::Entity.define_entity(:helipad, :building, 1_000, 100, "Builds and rearms aircraft", tiles) do |entity|
|
||||
unless entity.proto_entity
|
||||
entity.has(:building)
|
||||
entity.has(:waypoint)
|
||||
entity.has(:spawner)
|
||||
entity.has(:build_queue)
|
||||
entity.has(:sidebar_actions)
|
||||
entity.component(:sidebar_actions).add(:add_to_build_queue, { entity: :helicopter })
|
||||
end
|
||||
|
||||
entity.radius = 26
|
||||
entity.max_health = 100.0
|
||||
|
||||
@@ -7,7 +7,9 @@ tiles = [
|
||||
]
|
||||
|
||||
IMICRTS::Entity.define_entity(:power_plant, :building, 800, 45, "Generates power", tiles) do |entity|
|
||||
entity.has(:building)
|
||||
unless entity.proto_entity
|
||||
entity.has(:building)
|
||||
end
|
||||
|
||||
entity.radius = 24
|
||||
entity.max_health = 100.0
|
||||
@@ -29,14 +31,13 @@ IMICRTS::Entity.define_entity(:power_plant, :building, 800, 45, "Generates power
|
||||
|
||||
|
||||
emitters.each do |pos|
|
||||
entity.particle_emitters << IMICRTS::SmokeEmitter.new(position: pos)
|
||||
entity.particle_emitters << IMICRTS::SmokeEmitter.new(position: pos, emitting: false)
|
||||
end
|
||||
|
||||
entity.on_tick do
|
||||
# entity.produce_power
|
||||
|
||||
if entity.component(:building).data.state == :idle
|
||||
|
||||
if entity.component(:building).construction_complete?
|
||||
entity.particle_emitters.each do |emitter|
|
||||
emitter.emitting = true
|
||||
end
|
||||
|
||||
@@ -7,7 +7,9 @@ tiles = [
|
||||
]
|
||||
|
||||
IMICRTS::Entity.define_entity(:refinery, :building, 1_400, 200, "Generates credits", tiles) do |entity|
|
||||
entity.has(:building)
|
||||
unless entity.proto_entity
|
||||
entity.has(:building)
|
||||
end
|
||||
|
||||
entity.radius = 44
|
||||
entity.max_health = 100.0
|
||||
|
||||
@@ -6,15 +6,17 @@ tiles = [
|
||||
[false, :path, :path, :path, false],
|
||||
]
|
||||
|
||||
IMICRTS::Entity.define_entity(:war_factory, :building, 2_000, 310, "Builds units", tiles) do |entity|
|
||||
entity.has(:building)
|
||||
entity.has(:waypoint)
|
||||
entity.has(:spawner)
|
||||
entity.has(:build_queue)
|
||||
entity.has(:sidebar_actions)
|
||||
entity.component(:sidebar_actions).add(:add_to_build_queue, { entity: :jeep })
|
||||
entity.component(:sidebar_actions).add(:add_to_build_queue, { entity: :tank })
|
||||
entity.component(:sidebar_actions).add(:add_to_build_queue, { entity: :harvester })
|
||||
IMICRTS::Entity.define_entity(:war_factory, :building, 2_000, 310, "Builds and repairs ground vehicles", tiles) do |entity|
|
||||
unless entity.proto_entity
|
||||
entity.has(:building)
|
||||
entity.has(:waypoint)
|
||||
entity.has(:spawner)
|
||||
entity.has(:build_queue)
|
||||
entity.has(:sidebar_actions)
|
||||
entity.component(:sidebar_actions).add(:add_to_build_queue, { entity: :jeep })
|
||||
entity.component(:sidebar_actions).add(:add_to_build_queue, { entity: :tank })
|
||||
entity.component(:sidebar_actions).add(:add_to_build_queue, { entity: :harvester })
|
||||
end
|
||||
|
||||
entity.radius = 48
|
||||
entity.max_health = 100.0
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
IMICRTS::Entity.define_entity(:construction_worker, :unit, 1000, 75, "Constructs buildings") do |entity|
|
||||
entity.has(:movement)
|
||||
entity.has(:build_queue)
|
||||
entity.has(:sidebar_actions)
|
||||
[:power_plant, :refinery, :barracks, :war_factory, :helipad, :construction_yard].each do |ent|
|
||||
entity.component(:sidebar_actions).add(:set_tool, { tool: :place_entity, entity: ent, construction_worker: entity })
|
||||
unless entity.proto_entity
|
||||
entity.has(:movement)
|
||||
entity.has(:build_queue)
|
||||
entity.has(:sidebar_actions)
|
||||
[:power_plant, :refinery, :barracks, :war_factory, :helipad, :construction_yard].each do |ent|
|
||||
entity.component(:sidebar_actions).add(:set_tool, { tool: :place_entity, entity: ent, construction_worker: entity })
|
||||
end
|
||||
end
|
||||
|
||||
entity.radius = 14
|
||||
|
||||
@@ -14,7 +14,7 @@ class IMICRTS
|
||||
@entities[name] = Stub.new(name, type, cost, build_steps, description, tiles, block)
|
||||
end
|
||||
|
||||
attr_reader :director, :player, :id, :name, :type, :data
|
||||
attr_reader :director, :player, :id, :name, :type, :data, :proto_entity
|
||||
attr_accessor :position, :angle, :radius, :target, :state, :movement, :health, :max_health,
|
||||
:speed, :turret, :center, :particle_emitters, :color
|
||||
|
||||
@@ -123,10 +123,14 @@ class IMICRTS
|
||||
end
|
||||
|
||||
def render
|
||||
turret = component(:turret).render if component(:turret) && @proto_entity
|
||||
|
||||
@render = Gosu.render(@shell_image.width, @shell_image.height, retro: true) do
|
||||
@body_image.draw(0, 0, 0) if @body_image
|
||||
@shell_image.draw(0, 0, 0, 1, 1, @player.color)
|
||||
@overlay_image.draw(0, 0, 0) if @overlay_image
|
||||
|
||||
turret.draw(0, 0, 2) if component(:turret) && @proto_entity
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ class IMICRTS
|
||||
class Game < CyberarmEngine::GuiState
|
||||
Overlay = Struct.new(:image, :position, :angle, :alpha)
|
||||
|
||||
attr_reader :sidebar, :sidebar_actions, :overlays, :director
|
||||
attr_reader :sidebar, :sidebar_title, :sidebar_actions, :overlays, :director
|
||||
attr_accessor :selected_entities
|
||||
|
||||
def setup
|
||||
@@ -23,11 +23,6 @@ class IMICRTS
|
||||
@director.add_player(player)
|
||||
end
|
||||
|
||||
# @player = Player.new(id: 0, spawnpoint: @director.map.spawnpoints.last)
|
||||
# @player2 = Player.new(id: 1, spawnpoint: @director.map.spawnpoints.first)
|
||||
# @director.add_player(@player)
|
||||
# @director.add_player(@player2)
|
||||
|
||||
@selected_entities = []
|
||||
@tool = set_tool(:entity_controller)
|
||||
@overlays = []
|
||||
@@ -35,12 +30,21 @@ class IMICRTS
|
||||
@debug_info = CyberarmEngine::Text.new("", y: 10, z: Float::INFINITY, shadow_color: Gosu::Color.rgba(0, 0, 0, 200))
|
||||
|
||||
@sidebar = stack(width: IMICRTS::MENU_WIDTH, height: 1.0, padding: IMICRTS::MENU_PADDING) do
|
||||
background [0x55555555, 0x55666666]
|
||||
background [0xff555555, 0xff666666]
|
||||
|
||||
banner "SIDEBAR", margin_bottom: 20
|
||||
@sidebar_radar = stack(width: 1.0) do
|
||||
image @director.map.render_preview, width: 1.0
|
||||
end
|
||||
|
||||
flow(width: 1.0) do
|
||||
para "$10,000", width: 0.49
|
||||
para "Power 250/250", width: 0.49, text_align: :right
|
||||
end
|
||||
|
||||
@sidebar_title = title ""
|
||||
|
||||
flow(width: 1.0, height: 1.0) do
|
||||
@sidebar_actions = stack(width: 0.9) do
|
||||
@sidebar_actions = flow(width: 0.9) do
|
||||
end
|
||||
|
||||
# Power meter
|
||||
@@ -69,13 +73,13 @@ class IMICRTS
|
||||
position: CyberarmEngine::Vector.new(player.spawnpoint.x - 64, player.spawnpoint.y + 64, ZOrder::GROUND_VEHICLE)
|
||||
)
|
||||
end
|
||||
|
||||
button_down(Gosu::KB_H) if @player
|
||||
end
|
||||
|
||||
def draw
|
||||
super
|
||||
|
||||
# Gosu.draw_rect(0, 0, window.width, window.height, Gosu::Color.rgb(10, 175, 35))
|
||||
|
||||
@player.camera.draw do
|
||||
@director.map.draw(@player.camera)
|
||||
@director.entities.each(&:draw)
|
||||
@@ -122,6 +126,10 @@ class IMICRTS
|
||||
).lines.map { |line| line.strip }.join("\n")
|
||||
|
||||
@debug_info.x = @sidebar.width + 20
|
||||
|
||||
# entity = @director.players.map { |pl| pl.entities.find { |ent| mouse.distance(ent.position) <= ent.radius } }.first
|
||||
# @tip.value = "#{entity.player.name}: #{entity.name}" if entity
|
||||
# @tip.value = "" unless entity
|
||||
end
|
||||
|
||||
def button_down(id)
|
||||
|
||||
@@ -4,6 +4,7 @@ class IMICRTS
|
||||
red: Gosu::Color::RED,
|
||||
lightblue: Gosu::Color.rgb(100, 100, 255),
|
||||
blue: Gosu::Color::BLUE,
|
||||
purple: Gosu::Color::FUCHSIA,
|
||||
lime: Gosu::Color::GREEN,
|
||||
lightgreen: Gosu::Color.rgb(50, 200, 50),
|
||||
green: Gosu::Color.rgb(0, 200, 0),
|
||||
|
||||
@@ -70,6 +70,7 @@ class IMICRTS
|
||||
|
||||
diff = (@player.selected_entities - @game.selected_entities)
|
||||
@game.sidebar_actions.clear
|
||||
@game.sidebar_title.value = ""
|
||||
|
||||
@director.schedule_order(Order::DESELECTED_UNITS, @player.id, diff) if diff.size.positive?
|
||||
if @game.selected_entities.size.positive?
|
||||
@@ -81,9 +82,11 @@ class IMICRTS
|
||||
if @game.selected_entities.size < 2 && ent = @game.selected_entities.first
|
||||
return unless ent.component(:sidebar_actions)
|
||||
|
||||
@game.sidebar_title.value = ent.name.to_s.split("_").map { |s| s.capitalize }.join(" ")
|
||||
|
||||
@game.sidebar_actions.clear do
|
||||
ent.component(:sidebar_actions).actions.each do |action|
|
||||
@game.button action.label, tip: action.description, width: 1.0 do
|
||||
@game.button action.image, tip: action.description, image_width: 0.30 do
|
||||
action.block&.call
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user