mirror of
https://github.com/cyberarm/i-mic-rts.git
synced 2025-12-14 07:12:34 +00:00
Entities are now definable
This commit is contained in:
11
lib/entities/construction_worker.rb
Normal file
11
lib/entities/construction_worker.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
IMICRTS::Entity.define_entity(:construction_worker, :unit, 1000, "Constructs buildings") do |entity|
|
||||
entity.radius = 14
|
||||
entity.movement = :ground
|
||||
entity.max_health = 100.0
|
||||
|
||||
entity.body_image = "vehicles/construction_worker/images/construction_worker.png"
|
||||
entity.shell_image = "vehicles/construction_worker/images/construction_worker.png"
|
||||
|
||||
entity.on_tick do
|
||||
end
|
||||
end
|
||||
34
lib/entities/harvester.rb
Normal file
34
lib/entities/harvester.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
IMICRTS::Entity.define_entity(:harvester, :unit, 1400, "Harvests ore") do |entity, director|
|
||||
entity.radius = 10
|
||||
entity.movement = :ground
|
||||
entity.max_health = 100.0
|
||||
|
||||
entity.body_image = "vehicles/harvester/images/harvester.png"
|
||||
entity.shell_image = "vehicles/harvester/images/harvester.png"
|
||||
|
||||
@capacity = 10.0
|
||||
@bed = 0.0
|
||||
|
||||
entity.on_tick do
|
||||
if @bed >= @capacity
|
||||
entity.seek_refinery
|
||||
else
|
||||
entity.seek_ore
|
||||
end
|
||||
end
|
||||
|
||||
entity.define_singleton_method(:seek_ore) do
|
||||
ore = director.map.ores.compact.sort_by { |ore| next unless ore; ore.position.distance(entity.position) }.first
|
||||
|
||||
n = (ore.position - entity.position).normalized
|
||||
n.z = 0
|
||||
entity.position += n * 3
|
||||
end
|
||||
|
||||
entity.define_singleton_method(:seek_refinery) do
|
||||
end
|
||||
|
||||
entity.define_singleton_method(:rotate_towards) do |target|
|
||||
entity.angle = Gosu.angle(target.x, target.y, entity.position.x, entity.position.y)
|
||||
end
|
||||
end
|
||||
15
lib/entities/power_plant.rb
Normal file
15
lib/entities/power_plant.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
IMICRTS::Entity.define_entity(:power_plant, :building, 800, "Generates power") do |entity|
|
||||
entity.radius = 14
|
||||
entity.max_health = 100.0
|
||||
|
||||
entity.body_image = "vehicles/power_plant/images/power_plant.png"
|
||||
entity.shell_image = "vehicles/power_plant/images/power_plant.png"
|
||||
|
||||
entity.on_tick do
|
||||
entity.produce_power
|
||||
end
|
||||
|
||||
define_singleton_method(:produce_power) do
|
||||
@player.power += 10
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user