Implemented Zoom

This commit is contained in:
2019-10-01 08:25:02 -05:00
parent 79de34a596
commit 51db2dc5b8
4 changed files with 48 additions and 20 deletions

View File

@@ -6,19 +6,18 @@ class IMICRTS
@mouse_pos = CyberarmEngine::Text.new("X: 0\nY: 0", x: 500, y: 10, z: Float::INFINITY)
@sidebar = stack(height: 1.0) do
background [0xff555555, Gosu::Color::GRAY]
background [0x55555555, 0x55666666]
label "SIDEBAR", text_size: 78
label ""
label "SIDEBAR", text_size: 78, margin_bottom: 20
button("Harvest", width: 1.0) do
@h = button("Harvester", width: 1.0) do
@units << Entity.new(
images: Gosu::Image.new("assets/vehicles/harvester/images/harvester.png", retro: true),
position: CyberarmEngine::Vector.new(rand(window.width), rand(window.height), ZOrder::GROUND_VEHICLE),
angle: rand(360)
)
end
button("Construction Worker", width: 1.0) do
@c = button("Construction Worker", width: 1.0) do
@units << Entity.new(
images: Gosu::Image.new("assets/vehicles/construction_worker/images/construction_worker.png", retro: true),
position: CyberarmEngine::Vector.new(rand(window.width), rand(window.height), ZOrder::GROUND_VEHICLE),
@@ -27,11 +26,13 @@ class IMICRTS
end
button("Leave", width: 1.0) do
button("Leave", width: 1.0, margin_top: 20) do
finalize
push_state(MainMenu)
end
end
100.times { |i| [@c, @h].sample.instance_variable_get("@block").call }
end
def draw
@@ -43,10 +44,10 @@ class IMICRTS
@units.each(&:draw)
draw_rect(@anchor.x - 10, @anchor.y - 10, 20, 20, Gosu::Color::RED, Float::INFINITY) if @anchor
# draw_rect(@camera.center.x - 10, @camera.center.y - 10, 20, 20, Gosu::Color::BLACK, Float::INFINITY)
draw_rect(@camera.center.x - 10, @camera.center.y - 10, 20, 20, Gosu::Color::BLACK, Float::INFINITY)
# mouse_center = CyberarmEngine::Vector.new(window.mouse_x, window.mouse_y) - @camera.position
# draw_rect(mouse_center.x - 10, mouse_center.y - 10, 20, 20, Gosu::Color::YELLOW, Float::INFINITY)
mouse = @camera.mouse_pick(window.mouse_x, window.mouse_y)
draw_rect(mouse.x - 10, mouse.y - 10, 20, 20, Gosu::Color::YELLOW, Float::INFINITY)
end
@mouse_pos.draw
@@ -61,7 +62,8 @@ class IMICRTS
@camera.center_around(@anchor, 0.9)
end
@mouse_pos.text = "X: #{window.mouse_x}\nY: #{window.mouse_y}"
mouse = @camera.mouse_pick(window.mouse_x, window.mouse_y)
@mouse_pos.text = "Zoom: #{@camera.zoom}\nX: #{window.mouse_x}\nY: #{window.mouse_y}\n\nX: #{mouse.x}\nY: #{mouse.y}"
end
def button_down(id)
@@ -70,12 +72,12 @@ class IMICRTS
case id
when Gosu::MS_LEFT
unless @sidebar.hit?(window.mouse_x, window.mouse_y)
@anchor = CyberarmEngine::Vector.new(window.mouse_x, window.mouse_y) - @camera.position
@anchor = @camera.mouse_pick(window.mouse_x, window.mouse_y)
end
when Gosu::MS_RIGHT
@anchor = nil
end
@camera.button_down(id)
@camera.button_down(id) unless @sidebar.hit?(window.mouse_x, window.mouse_y)
end
def button_up(id)