Tacked on 'Overlays' to place a move cursor for move orders, TODO: Refactor into its own class

This commit is contained in:
2019-10-27 12:07:30 -05:00
parent cd7b71894d
commit a1999d7c6f
3 changed files with 16 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
class IMICRTS class IMICRTS
class Game < CyberarmEngine::GuiState class Game < CyberarmEngine::GuiState
Overlay = Struct.new(:image, :position, :angle, :alpha)
def setup def setup
window.show_cursor = true window.show_cursor = true
@@ -7,6 +8,7 @@ class IMICRTS
@director = Director.new(map: Map.new(map_file: "maps/test_map.tmx"), players: [@player]) @director = Director.new(map: Map.new(map_file: "maps/test_map.tmx"), players: [@player])
@selected_entities = [] @selected_entities = []
@overlays = []
@debug_info = CyberarmEngine::Text.new("", y: 10, z: Float::INFINITY, shadow_color: Gosu::Color.rgba(0, 0, 0, 200)) @debug_info = CyberarmEngine::Text.new("", y: 10, z: Float::INFINITY, shadow_color: Gosu::Color.rgba(0, 0, 0, 200))
@@ -75,16 +77,15 @@ class IMICRTS
@director.entities.each(&:draw) @director.entities.each(&:draw)
@selected_entities.each(&:selected_draw) @selected_entities.each(&:selected_draw)
# center = @player.camera.center - @player.camera.position @overlays.each do |overlay|
# draw_rect(center.x - 10, center.y - 10, 20, 20, Gosu::Color::RED, Float::INFINITY) overlay.image.draw_rot(overlay.position.x, overlay.position.y, overlay.position.z, overlay.angle, 0.5, 0.5, 1, 1, Gosu::Color.rgba(255, 255, 255, overlay.alpha))
overlay.angle += 3.0
overlay.alpha -= 5.0
# mouse = @player.camera.transform(window.mouse) @overlays.delete(overlay) if overlay.alpha <= 0
# draw_rect(mouse.x - 10, mouse.y - 10, 20, 20, Gosu::Color::YELLOW, Float::INFINITY) end
# Goal Gosu.draw_rect(@box.min.x, @box.min.y, @box.width, @box.height, Gosu::Color.rgba(50, 50, 50, 150), ZOrder::SELECTION_BOX) if @box
# draw_rect(@goal.x - 10, @goal.y - 10, 20, 20, Gosu::Color::WHITE, Float::INFINITY) if @goal
Gosu.draw_rect(@box.min.x, @box.min.y, @box.width, @box.height, Gosu::Color.rgba(50, 50, 50, 150), Float::INFINITY) if @box
end end
@debug_info.draw if Setting.enabled?(:debug_info_bar) @debug_info.draw if Setting.enabled?(:debug_info_bar)
@@ -135,6 +136,9 @@ class IMICRTS
end end
when Gosu::MS_RIGHT when Gosu::MS_RIGHT
@director.schedule_order(Order::MOVE, @player.id, @player.camera.transform(window.mouse)) @director.schedule_order(Order::MOVE, @player.id, @player.camera.transform(window.mouse))
@overlays << Overlay.new(Gosu::Image.new("#{IMICRTS::ASSETS_PATH}/cursors/move.png"), @player.camera.transform(window.mouse), 0, 255)
@overlays.last.position.z = ZOrder::OVERLAY
end end
@player.camera.button_down(id) unless @sidebar.hit?(window.mouse_x, window.mouse_y) @player.camera.button_down(id) unless @sidebar.hit?(window.mouse_x, window.mouse_y)

View File

@@ -17,7 +17,7 @@ class IMICRTS
end end
def draw def draw
@cursor.draw(mouse_x, mouse_y, Float::INFINITY) @cursor.draw(mouse_x, mouse_y, Float::INFINITY) if @show_cursor
super super
end end

View File

@@ -11,6 +11,9 @@ class IMICRTS
:ENTITY_RADIUS, :ENTITY_RADIUS,
:ENTITY_GIZMOS, # Health bar and the like :ENTITY_GIZMOS, # Health bar and the like
:OVERLAY,
:SELECTION_BOX,
] ]
enum.each_with_index do |constant, index| enum.each_with_index do |constant, index|