mirror of
https://github.com/cyberarm/i-mic-rts.git
synced 2025-12-15 07:42:34 +00:00
Improved place buildings tool to use the grid
This commit is contained in:
@@ -1,4 +1,12 @@
|
|||||||
IMICRTS::Entity.define_entity(:barracks, :building, 400, "Builds and soldiers") do |entity|
|
tiles = [
|
||||||
|
[false, false, false, false, false],
|
||||||
|
[false, true, true, true, false],
|
||||||
|
[false, true, true, true, false],
|
||||||
|
[false, true, true, true, false],
|
||||||
|
[false, true, true, true, false],
|
||||||
|
]
|
||||||
|
|
||||||
|
IMICRTS::Entity.define_entity(:barracks, :building, 400, "Builds and soldiers", tiles) do |entity|
|
||||||
entity.has(:build_queue)
|
entity.has(:build_queue)
|
||||||
|
|
||||||
entity.radius = 44
|
entity.radius = 44
|
||||||
|
|||||||
@@ -1,4 +1,12 @@
|
|||||||
IMICRTS::Entity.define_entity(:construction_yard, :building, 2_000, "Provides radar and builds construction workers") do |entity|
|
tiles = [
|
||||||
|
[false, false, false, false, false],
|
||||||
|
[false, true, true, true, false],
|
||||||
|
[false, true, true, true, false],
|
||||||
|
[false, true, true, true, false],
|
||||||
|
[false, true, true, true, false],
|
||||||
|
]
|
||||||
|
|
||||||
|
IMICRTS::Entity.define_entity(:construction_yard, :building, 2_000, "Provides radar and builds construction workers", tiles) do |entity|
|
||||||
entity.has(:build_queue)
|
entity.has(:build_queue)
|
||||||
entity.has(:sidebar_actions)
|
entity.has(:sidebar_actions)
|
||||||
entity.component(:sidebar_actions).add(:add_to_build_queue, {entity: :construction_worker})
|
entity.component(:sidebar_actions).add(:add_to_build_queue, {entity: :construction_worker})
|
||||||
|
|||||||
@@ -1,4 +1,12 @@
|
|||||||
IMICRTS::Entity.define_entity(:helipad, :building, 1_000, "Builds and rearms helicopters") do |entity|
|
tiles = [
|
||||||
|
[false, false, false, false, false],
|
||||||
|
[false, false, true, false, false],
|
||||||
|
[false, true, true, true, false],
|
||||||
|
[false, false, true, false, false],
|
||||||
|
[false, false, false, false, false],
|
||||||
|
]
|
||||||
|
|
||||||
|
IMICRTS::Entity.define_entity(:helipad, :building, 1_000, "Builds and rearms helicopters", tiles) do |entity|
|
||||||
entity.has(:build_queue)
|
entity.has(:build_queue)
|
||||||
entity.has(:sidebar_actions)
|
entity.has(:sidebar_actions)
|
||||||
entity.component(:sidebar_actions).add(:add_to_build_queue, {entity: :helicopter})
|
entity.component(:sidebar_actions).add(:add_to_build_queue, {entity: :helicopter})
|
||||||
|
|||||||
@@ -1,4 +1,12 @@
|
|||||||
IMICRTS::Entity.define_entity(:power_plant, :building, 800, "Generates power") do |entity|
|
tiles = [
|
||||||
|
[false, false, false, false, false],
|
||||||
|
[false, false, false, false, false],
|
||||||
|
[false, false, true, false, false],
|
||||||
|
[false, false, true, false, false],
|
||||||
|
[false, false, true, false, false],
|
||||||
|
]
|
||||||
|
|
||||||
|
IMICRTS::Entity.define_entity(:power_plant, :building, 800, "Generates power", tiles) do |entity|
|
||||||
entity.radius = 24
|
entity.radius = 24
|
||||||
entity.max_health = 100.0
|
entity.max_health = 100.0
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,12 @@
|
|||||||
IMICRTS::Entity.define_entity(:refinery, :building, 1_400, "Generates credits") do |entity|
|
tiles = [
|
||||||
|
[false, false, false, false, false],
|
||||||
|
[false, true, true, true, false],
|
||||||
|
[false, true, true, true, false],
|
||||||
|
[false, true, true, true, false],
|
||||||
|
[false, true, true, true, false],
|
||||||
|
]
|
||||||
|
|
||||||
|
IMICRTS::Entity.define_entity(:refinery, :building, 1_400, "Generates credits", tiles) do |entity|
|
||||||
entity.radius = 44
|
entity.radius = 44
|
||||||
entity.max_health = 100.0
|
entity.max_health = 100.0
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,12 @@
|
|||||||
IMICRTS::Entity.define_entity(:war_factory, :building, 2_000, "Builds units") do |entity|
|
tiles = [
|
||||||
|
[false, false, false, false, false],
|
||||||
|
[false, true, true, true, false],
|
||||||
|
[false, true, true, true, false],
|
||||||
|
[false, true, true, true, false],
|
||||||
|
[false, true, true, true, false],
|
||||||
|
]
|
||||||
|
|
||||||
|
IMICRTS::Entity.define_entity(:war_factory, :building, 2_000, "Builds units", tiles) do |entity|
|
||||||
entity.has(:build_queue)
|
entity.has(:build_queue)
|
||||||
entity.has(:sidebar_actions)
|
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: :jeep})
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
class IMICRTS
|
class IMICRTS
|
||||||
class Entity
|
class Entity
|
||||||
Stub = Struct.new(:name, :type, :cost, :description, :setup)
|
Stub = Struct.new(:name, :type, :cost, :description, :tiles, :setup)
|
||||||
@entities = {}
|
@entities = {}
|
||||||
|
|
||||||
def self.get(name)
|
def self.get(name)
|
||||||
@entities.dig(name)
|
@entities.dig(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.define_entity(name, type, cost, description, &block)
|
def self.define_entity(name, type, cost, description, tiles = [[]], &block)
|
||||||
if entity = get(name)
|
if entity = get(name)
|
||||||
raise "#{name.inspect} is already defined!"
|
raise "#{name.inspect} is already defined!"
|
||||||
else
|
else
|
||||||
@entities[name] = Stub.new(name, type, cost, description, block)
|
@entities[name] = Stub.new(name, type, cost, description, tiles, block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
14
lib/tool.rb
14
lib/tool.rb
@@ -41,6 +41,20 @@ class IMICRTS
|
|||||||
def cancel_tool
|
def cancel_tool
|
||||||
@game.set_tool(nil)
|
@game.set_tool(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def use_tool(vector, options = {})
|
||||||
|
end
|
||||||
|
|
||||||
|
def can_use?(vector)
|
||||||
|
end
|
||||||
|
|
||||||
|
def vector_to_grid(vector)
|
||||||
|
temp = @player.camera.transform(vector)
|
||||||
|
temp.x = (temp.x / @director.map.tile_size).floor
|
||||||
|
temp.y = (temp.y / @director.map.tile_size).floor
|
||||||
|
|
||||||
|
return temp
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -17,12 +17,33 @@ class IMICRTS
|
|||||||
def update
|
def update
|
||||||
# TODO: ensure that construction worker is alive
|
# TODO: ensure that construction worker is alive
|
||||||
cancel_tool if @construction_worker.die?
|
cancel_tool if @construction_worker.die?
|
||||||
@preview.position = @player.camera.transform(@game.window.mouse)
|
vector = vector_to_grid(@game.window.mouse)
|
||||||
@preview.position.z = ZOrder::OVERLAY
|
if tile = @director.map.tile_at(vector.x, vector.y)
|
||||||
|
position = tile.position.clone
|
||||||
|
@preview.position = position
|
||||||
|
@preview.position.z = ZOrder::OVERLAY
|
||||||
|
else
|
||||||
|
@preview.position.z = -10
|
||||||
|
end
|
||||||
|
|
||||||
@preview.color.alpha = 150
|
@preview.color.alpha = 150
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def use_tool(vector)
|
||||||
|
return if @game.sidebar.hit?(@game.window.mouse_x, @game.window.mouse_y)
|
||||||
|
|
||||||
|
tile = @director.map.tile_at(vector.x, vector.y)
|
||||||
|
return unless tile
|
||||||
|
position = tile.position.clone
|
||||||
|
|
||||||
|
@director.spawn_entity(
|
||||||
|
player_id: @player.id, name: @entity,
|
||||||
|
position: CyberarmEngine::Vector.new(position.x, position.y, ZOrder::BUILDING)
|
||||||
|
)
|
||||||
|
|
||||||
|
cancel_tool
|
||||||
|
end
|
||||||
|
|
||||||
def button_down(id)
|
def button_down(id)
|
||||||
case id
|
case id
|
||||||
when Gosu::MsRight
|
when Gosu::MsRight
|
||||||
@@ -33,16 +54,7 @@ class IMICRTS
|
|||||||
def button_up(id)
|
def button_up(id)
|
||||||
case id
|
case id
|
||||||
when Gosu::MsLeft
|
when Gosu::MsLeft
|
||||||
return if @game.sidebar.hit?(@game.window.mouse_x, @game.window.mouse_y)
|
use_tool(vector_to_grid(@game.window.mouse))
|
||||||
|
|
||||||
transform = @player.camera.transform(@game.window.mouse)
|
|
||||||
|
|
||||||
@director.spawn_entity(
|
|
||||||
player_id: @player.id, name: @entity,
|
|
||||||
position: CyberarmEngine::Vector.new(transform.x, transform.y, ZOrder::BUILDING)
|
|
||||||
)
|
|
||||||
|
|
||||||
cancel_tool
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user