diff --git a/i-mic-rts.rb b/i-mic-rts.rb index a3e9080..ab6ff71 100644 --- a/i-mic-rts.rb +++ b/i-mic-rts.rb @@ -18,4 +18,4 @@ require_relative "lib/zorder" require_relative "lib/entity" # require_relative "lib/entities/" -IMICRTS::Window.new(width: Gosu.screen_width, height: Gosu.screen_height, fullscreen: true).show \ No newline at end of file +IMICRTS::Window.new(width: Gosu.screen_width / 4 * 3, height: Gosu.screen_height / 4 * 3, fullscreen: false, resizable: true).show \ No newline at end of file diff --git a/lib/camera.rb b/lib/camera.rb index 9da221a..82bdb91 100644 --- a/lib/camera.rb +++ b/lib/camera.rb @@ -37,25 +37,20 @@ class IMICRTS def mouse_pick(x, y) mouse = CyberarmEngine::Vector.new(x, y) / @zoom - normalized = (mouse / @zoom - @position / @zoom) * @zoom - normalized.x = normalized.x.floor - normalized.y = normalized.y.floor + worldspace = (mouse - @position) + worldspace.x = worldspace.x.floor + worldspace.y = worldspace.y.floor - return normalized + return worldspace end def center - (CyberarmEngine::Vector.new(window.width / 2, window.height / 2) / @zoom - @position / @zoom) * @zoom + (CyberarmEngine::Vector.new(window.width / 2, window.height / 2) - @position) end def center_around(vector, factor) @velocity *= 0 - delta = lerp(self.center, vector, factor) - @position += delta * window.dt - end - - def lerp(vec1, vec2, factor) - (vec1 - vec2) * factor.clamp(0.0, 1.0) + @position += center.lerp(vector, factor) * window.dt end def aspect_ratio @@ -70,7 +65,7 @@ class IMICRTS if @drag_start @velocity *= 0.0 - @position = lerp(@position, CyberarmEngine::Vector.new(window.mouse_x, window.mouse_y) - @drag_start, @grab_drag) + @position = @position.lerp(@drag_start - CyberarmEngine::Vector.new(window.mouse_x, window.mouse_y), @grab_drag) end end @@ -84,15 +79,13 @@ class IMICRTS when Gosu::MS_WHEEL_DOWN @zoom = (@zoom - 0.25).clamp(@min_zoom, @max_zoom) when Gosu::MS_MIDDLE - @position_start = @position.clone - @drag_start = CyberarmEngine::Vector.new(window.mouse_x, window.mouse_y) + @drag_start = CyberarmEngine::Vector.new(window.mouse_x, window.mouse_y) - @position end end def button_up(id) case id when Gosu::MS_MIDDLE - @position_start = nil @drag_start = nil end end diff --git a/lib/states/boot.rb b/lib/states/boot.rb index 218c9bc..c6e889b 100644 --- a/lib/states/boot.rb +++ b/lib/states/boot.rb @@ -4,7 +4,7 @@ class IMICRTS @title = Gosu::Font.new(56, name: "Noto Sans Display", bold: true) @text = Gosu::Font.new(18, name: "Noto Sans Thaana", bold: true) @name = IMICRTS::NAME - @logo = Gosu::Image.new("assets/logo.png") + @logo = Gosu::Image.new("#{ASSETS_PATH}/logo.png") @messages = ["Loading", "Compiling Protons", "Launching Warhead", "git push origin --force"] @messages_index = 0 @@ -30,39 +30,35 @@ class IMICRTS @background = Gosu::Color.new(0x007a0d71) @background_two = Gosu::Color.new(0x007b6ead) - - $window.width = Gosu.screen_width - $window.height = Gosu.screen_height - $window.fullscreen = true end def draw Gosu.draw_quad( 0, 0, @background_two, - $window.width, 0, @background, - 0, $window.height, @background, - $window.width, $window.height, @background_two + window.width, 0, @background, + 0, window.height, @background, + window.width, window.height, @background_two ) Gosu.draw_rect( - 0, $window.height/2 - 35, - $window.width, 71, + 0, window.height/2 - 35, + window.width, 71, Gosu::Color.new(0xff949dad) ) c = Gosu::Color.new(0xff55dae1) c2 = Gosu::Color.new(0xff3c9ec5) Gosu.draw_quad( - 0, $window.height/2 - 30, c, - $window.width, $window.height/2 - 30, c2, - 0, $window.height/2 + 30, c, - $window.width, $window.height/2 + 30, c2 + 0, window.height/2 - 30, c, + window.width, window.height/2 - 30, c2, + 0, window.height/2 + 30, c, + window.width, window.height/2 + 30, c2 ) - @logo.draw($window.width/2 - @logo.width/2, $window.height/2 - (@logo.height/3 + 14), 0) + @logo.draw(window.width/2 - @logo.width/2, window.height/2 - (@logo.height/3 + 14), 0) - @text.draw_text(@status, $window.width - (@text.text_width(@status.gsub(".", "")) + @text.text_width("...")), $window.height - @text.height, 0) + @text.draw_text(@status, window.width - (@text.text_width(@status.gsub(".", "")) + @text.text_width("...")), window.height - @text.height, 0) end def update diff --git a/lib/states/closing.rb b/lib/states/closing.rb index 768fe8c..d51a982 100644 --- a/lib/states/closing.rb +++ b/lib/states/closing.rb @@ -1,7 +1,7 @@ class IMICRTS class Closing < CyberarmEngine::GuiState def setup - @logo = Gosu::Image.new("assets/logo.png") + @logo = Gosu::Image.new("#{ASSETS_PATH}/logo.png") @color = Gosu::Color.new(0xffffffff) @started_at = Gosu.milliseconds diff --git a/lib/states/game.rb b/lib/states/game.rb index 35beddc..221fea2 100644 --- a/lib/states/game.rb +++ b/lib/states/game.rb @@ -12,14 +12,14 @@ class IMICRTS @h = button("Harvester", width: 1.0) do @units << Entity.new( - images: Gosu::Image.new("assets/vehicles/harvester/images/harvester.png", retro: true), + images: Gosu::Image.new("#{ASSETS_PATH}/vehicles/harvester/images/harvester.png", retro: true), position: CyberarmEngine::Vector.new(rand(window.width), rand(window.height), ZOrder::GROUND_VEHICLE), angle: rand(360) ) end @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), + images: Gosu::Image.new("#{ASSETS_PATH}/vehicles/construction_worker/images/construction_worker.png", retro: true), position: CyberarmEngine::Vector.new(rand(window.width), rand(window.height), ZOrder::GROUND_VEHICLE), angle: rand(360) ) diff --git a/lib/version.rb b/lib/version.rb index a20d09d..268c7fb 100644 --- a/lib/version.rb +++ b/lib/version.rb @@ -2,4 +2,7 @@ class IMICRTS NAME = "I-MIC RTS" VERSION = "0.0.1" VERSION_NAME = "InDev" + + GAME_ROOT_PATH = File.expand_path("../../", __FILE__) + ASSETS_PATH = "#{GAME_ROOT_PATH}/assets" end \ No newline at end of file