diff --git a/i-mic-fps.rb b/i-mic-fps.rb index e32469d..c1ae3ce 100644 --- a/i-mic-fps.rb +++ b/i-mic-fps.rb @@ -106,6 +106,7 @@ require_relative "lib/scenes/turn_table" require_relative "lib/crosshair" require_relative "lib/demo" +require_relative "lib/overlay" require_relative "lib/window" require_relative "lib/tools/asset_viewer" diff --git a/lib/map.rb b/lib/map.rb index 03311ab..1bee346 100644 --- a/lib/map.rb +++ b/lib/map.rb @@ -14,7 +14,6 @@ class IMICFPS @lights = [] @collision_manager = CollisionManager.new(map: self) - @renderer = window.renderer Publisher.new end @@ -54,7 +53,7 @@ class IMICFPS glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # clear the screen and the depth buffer gl_error? - @renderer.draw(camera, @lights, @entities) + window.renderer.draw(camera, @lights, @entities) end end diff --git a/lib/overlay.rb b/lib/overlay.rb new file mode 100644 index 0000000..b36b99f --- /dev/null +++ b/lib/overlay.rb @@ -0,0 +1,17 @@ +class IMICFPS + class Overlay + include CommonMethods + def initialize + @text = CyberarmEngine::Text.new("") + end + + def draw + Gosu.draw_rect(0, 0, 256, 20, Gosu::Color.rgba(0, 0, 0, 100)) + Gosu.draw_rect(2, 2, 256 - 4, 20 - 4, Gosu::Color.rgba(100, 100, 100, 100)) + @text.x = 3 + @text.y = 3 + @text.text = "FPS: #{Gosu.fps}" + @text.draw + end + end +end \ No newline at end of file diff --git a/lib/tools/asset_viewer/lib/turn_table.rb b/lib/tools/asset_viewer/lib/turn_table.rb index 085df2a..38209ef 100644 --- a/lib/tools/asset_viewer/lib/turn_table.rb +++ b/lib/tools/asset_viewer/lib/turn_table.rb @@ -31,7 +31,6 @@ class IMICFPS @lights << @light @camera = Camera.new(position: Vector.new(0, 1.5, 5), orientation: Vector.forward) - @renderer = Renderer.new label @manifest.name, text_size: 50 label @manifest.model @@ -55,7 +54,7 @@ class IMICFPS ) Gosu.gl do - @renderer.draw(@camera, [@light], @map.entities) + window.renderer.draw(@camera, [@light], @map.entities) end @crosshair.draw diff --git a/lib/tools/map_editor/lib/editor.rb b/lib/tools/map_editor/lib/editor.rb index 336f247..bf487b5 100644 --- a/lib/tools/map_editor/lib/editor.rb +++ b/lib/tools/map_editor/lib/editor.rb @@ -1,17 +1,58 @@ class IMICFPS class MapEditorTool class Editor < CyberarmEngine::GuiState + + attr_reader :map def setup - @map = Map.new( map_parser: @options[:map] ) - @camera = Camera.new( position: Vector.new, orientation: Vector.new(0, 90, 0) ) + # TODO: Move everything required for a playable game map + # in a Scene or Scene3D container object + # and refactor Game to use it. + Publisher.new + @map = Map.new( map_parser: @options[:map_parser] ) + @camera = Camera.new( position: Vector.new ) + @crosshair = Crosshair.new + + @map.setup end def draw - window.renderer.draw(@camera, @map.entities, @map.lights) + super + @map.render(@camera) + @crosshair.draw end def update - @camera.position.y -= 1 * window.dt + super + Publisher.instance.publish(:tick, Gosu.milliseconds - window.delta_time) + @map.update + @camera.update + end + + def button_down(id) + if id == Gosu::KB_ESCAPE + # TODO: Use Editor specific menu + push_state(GamePauseMenu) + + return + end + + InputMapper.keydown(id) + Publisher.instance.publish(:button_down, nil, id) + + @map.entities.each do |entity| + entity.button_down(id) if defined?(entity.button_down) + end + end + + def button_up(id) + InputMapper.keyup(id) + Publisher.instance.publish(:button_up, nil, id) + + @map.entities.each do |entity| + entity.button_up(id) if defined?(entity.button_up) + end + + @camera.button_up(id) end end end diff --git a/lib/ui/menus/main_menu.rb b/lib/ui/menus/main_menu.rb index db18d76..6e684a6 100644 --- a/lib/ui/menus/main_menu.rb +++ b/lib/ui/menus/main_menu.rb @@ -16,7 +16,7 @@ class IMICFPS push_state(ExtrasMenu) end - link "Exit" do + link "Exit Game" do window.close end diff --git a/lib/window.rb b/lib/window.rb index a416f4d..2502b2c 100644 --- a/lib/window.rb +++ b/lib/window.rb @@ -26,6 +26,7 @@ class IMICFPS @renderer = Renderer.new @renderer.preload_default_shaders @scene = TurnTableScene.new + @overlay = Overlay.new @canvas_size = Vector.new(self.width, self.height) @@ -46,6 +47,7 @@ class IMICFPS super @console.draw if @show_console + @overlay.draw draw_cursor if needs_cursor _canvas_size = Vector.new(self.width, self.height)