diff --git a/assets/vehicles/construction_worker/images/construction_worker.png b/assets/vehicles/construction_worker/images/construction_worker.png new file mode 100644 index 0000000..f6d1a65 Binary files /dev/null and b/assets/vehicles/construction_worker/images/construction_worker.png differ diff --git a/assets/vehicles/harvester/images/harvester.png b/assets/vehicles/harvester/images/harvester.png new file mode 100644 index 0000000..f524456 Binary files /dev/null and b/assets/vehicles/harvester/images/harvester.png differ diff --git a/i-mic-rts.rb b/i-mic-rts.rb index a858e7a..588e398 100644 --- a/i-mic-rts.rb +++ b/i-mic-rts.rb @@ -1,20 +1,19 @@ -require "base64" - begin require_relative "../cyberarm_engine/lib/cyberarm_engine" rescue LoadError require "cyberarm_engine" end +require_relative "lib/window" + require_relative "lib/states/boot" +require_relative "lib/states/game" +require_relative "lib/states/closing" +require_relative "lib/states/about_menu" require_relative "lib/states/main_menu" -class Window < CyberarmEngine::Engine - def setup - self.caption = "I-MIC RTS (#{Gosu.language})" - push_state(MainMenu) - end -end +require_relative "lib/zorder" +require_relative "lib/entity" +# require_relative "lib/entities/" -# Window.new(Gosu.screen_width, Gosu.screen_height, true).show -Window.new(width: Gosu.screen_width/2, height: Gosu.screen_height/2, fullscreen: false).show \ No newline at end of file +IMICRTS::Window.new(width: Gosu.screen_width, height: Gosu.screen_height, fullscreen: true).show \ No newline at end of file diff --git a/lib/entity.rb b/lib/entity.rb new file mode 100644 index 0000000..114682e --- /dev/null +++ b/lib/entity.rb @@ -0,0 +1,13 @@ +class IMICRTS + class Entity + def initialize(images:, position:, angle:) + @images = images + @position = position + @angle = angle + end + + def draw + @images.draw_rot(@position.x, @position.y, @position.z, @angle) + end + end +end \ No newline at end of file diff --git a/lib/states/about_menu.rb b/lib/states/about_menu.rb new file mode 100644 index 0000000..e1871ae --- /dev/null +++ b/lib/states/about_menu.rb @@ -0,0 +1,18 @@ +class IMICRTS + class AboutMenu < CyberarmEngine::GuiState + def setup + background [0xff7b6ead, 0xff7a0d71, 0xff7a0d71, 0xff7b6ead] + + stack(height: 1.0) do + background [0xff555555, Gosu::Color::GRAY] + + label "About I-MIC-RTS", text_size: 78, margin: 20 + label "Words go here.\nMore words also go here. Thank you and have a nice day." + + button("Back", width: 1.0) do + push_state(MainMenu) + end + end + end + end +end \ No newline at end of file diff --git a/lib/states/boot.rb b/lib/states/boot.rb index 7bfaf8e..79a374c 100644 --- a/lib/states/boot.rb +++ b/lib/states/boot.rb @@ -1,76 +1,78 @@ -class Boot < CyberarmEngine::GameState - def setup - @title = Gosu::Font.new(56, name: "Noto Sans Display", bold: true) - @text = Gosu::Font.new(18, name: "Noto Sans Thaana", bold: true) - @name = "I-MIC RTS" - @logo = Gosu::Image.new("assets/logo.png") +class IMICRTS + class Boot < CyberarmEngine::GameState + def setup + @title = Gosu::Font.new(56, name: "Noto Sans Display", bold: true) + @text = Gosu::Font.new(18, name: "Noto Sans Thaana", bold: true) + @name = "I-MIC RTS" + @logo = Gosu::Image.new("assets/logo.png") - @messages = ["Loading", "Compiling Protons", "Launching Warhead", "git push origin --force"] - @messages_index = 0 - @status = @messages[@messages_index] + @messages = ["Loading", "Compiling Protons", "Launching Warhead", "git push origin --force"] + @messages_index = 0 + @status = @messages[@messages_index] - @last_update = Gosu.milliseconds - @update_interval = 250 + @last_update = Gosu.milliseconds + @update_interval = 250 - @switcher = CyberarmEngine::Timer.new(5_000) do - push_state(MainMenu) - end - - @loader = CyberarmEngine::Timer.new(250) do - split = @status.scan(".") - if split.size >= 3 - @messages_index+=1 - @messages_index = 0 unless @messages_index < @messages.size - @status = @messages[@messages_index] - else - @status = "#{@status}." + @switcher = CyberarmEngine::Timer.new(5_000) do + push_state(MainMenu) end + + @loader = CyberarmEngine::Timer.new(250) do + split = @status.scan(".") + if split.size >= 3 + @messages_index+=1 + @messages_index = 0 unless @messages_index < @messages.size + @status = @messages[@messages_index] + else + @status = "#{@status}." + end + end + + @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 - @background = Gosu::Color.new(0x007a0d71) - @background_two = Gosu::Color.new(0x007b6ead) + 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 = Gosu.screen_width - $window.height = Gosu.screen_height - $window.fullscreen = true - end + Gosu.draw_rect( + 0, $window.height/2 - 35, + $window.width, 71, + Gosu::Color.new(0xff949dad) + ) - def draw - Gosu.draw_quad( - 0, 0, @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, - 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 - ) + 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 + ) - @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) - end + @text.draw_text(@status, $window.width - (@text.text_width(@status.gsub(".", "")) + @text.text_width("...")), $window.height - @text.height, 0) + end - def update - self.show_cursor = false + def update + self.show_cursor = false - @background.alpha+=1 - @background_two.alpha+=1 + @background.alpha+=1 + @background_two.alpha+=1 - @switcher.update - @loader.update + @switcher.update + @loader.update + end end end \ No newline at end of file diff --git a/lib/states/closing.rb b/lib/states/closing.rb new file mode 100644 index 0000000..7acc861 --- /dev/null +++ b/lib/states/closing.rb @@ -0,0 +1,28 @@ +class IMICRTS + class Closing < CyberarmEngine::GuiState + def setup + @logo = Gosu::Image.new("assets/logo.png") + @color = Gosu::Color.new(0xffffffff) + + @started_at = Gosu.milliseconds + @close_time = 3_000 + end + + def draw + Gosu.draw_rect(0, 0, window.width, window.height, @color) + @logo.draw(window.width / 2 - @logo.width / 2, window.height / 2 - @logo.height / 2, 2, 1.0, 1.0, @color) + end + + def update + super + factor = (1.0 - ((Gosu.milliseconds - @started_at) / @close_time.to_f)).clamp(0.0, 1.0) + @color.alpha = 255 * (factor - 0.1) + + window.close if Gosu.milliseconds - @started_at >= @close_time + end + + def button_up(id) + window.close if id == Gosu::KB_ESCAPE + end + end +end \ No newline at end of file diff --git a/lib/states/game.rb b/lib/states/game.rb new file mode 100644 index 0000000..740b17c --- /dev/null +++ b/lib/states/game.rb @@ -0,0 +1,47 @@ +class IMICRTS + class Game < CyberarmEngine::GuiState + def setup + @units = [] + + stack(height: 1.0) do + background [0xff555555, Gosu::Color::GRAY] + + label "SIDEBAR", text_size: 78 + label "" + + button("Harvest", 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 + @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), + angle: rand(360) + ) + end + + label "" + + button("Leave", width: 1.0) do + finalize + push_state(MainMenu) + end + end + end + + def draw + super + Gosu.draw_rect(0, 0, window.width, window.height, Gosu::Color.rgb(10, 175, 35)) + + @units.each(&:draw) + end + + def finalize + # TODO: Release bound objects/remove self from Window.states array + end + end +end \ No newline at end of file diff --git a/lib/states/main_menu.rb b/lib/states/main_menu.rb index 507ebc0..9b5f87d 100644 --- a/lib/states/main_menu.rb +++ b/lib/states/main_menu.rb @@ -1,53 +1,25 @@ -class MainMenu < CyberarmEngine::GuiState - def setup - self.show_cursor = true +class IMICRTS + class MainMenu < CyberarmEngine::GuiState + def setup + self.show_cursor = true - @container = stack do - background 0xff00aa00 + background [0xff7b6ead, 0xff7a0d71, 0xff7a0d71, 0xff7b6ead] - flow do - - stack(height: 1.0) do - background Gosu::Color.rgba(50, 50, 50, 200) - button("Play") - button("About") - button("Exit") do - $window.close - end + stack(height: 1.0) do + background [0xff555555, Gosu::Color::GRAY] + label "I-MIC-RTS", text_size: 78, margin: 20 + button("Play", width: 1.0) do + push_state(Game) end - stack do - image("assets/logo.png", height: 275) do - pop_state if previous_state - end + button("About", width: 1.0) do + push_state(AboutMenu) end - stack do - background Gosu::Color.rgba(50, 50, 50, 200) - - 1.times do - label "Username" - @username = edit_line "" - label "Password" - @password = edit_line "", type: :password - - check_box "Remember me?", checked: true - - flow do - button "Log In" do - push_state(Boot) - puts "Logging in... #{@username.value}:#{Base64.encode64(@password.value)}" - end - button "Sign Up" - - end - end + button("Exit", width: 1.0) do + push_state(Closing) end end end - - $window.width = @container.width - $window.height = @container.height - $window.fullscreen = false end end \ No newline at end of file diff --git a/lib/window.rb b/lib/window.rb new file mode 100644 index 0000000..e913463 --- /dev/null +++ b/lib/window.rb @@ -0,0 +1,11 @@ +class IMICRTS + class Window < CyberarmEngine::Engine + def setup + Gosu.milliseconds # Start counter + + self.caption = "I-MIC RTS (#{Gosu.language})" + push_state(Boot) + # push_state(MainMenu) + end + end +end \ No newline at end of file diff --git a/lib/zorder.rb b/lib/zorder.rb new file mode 100644 index 0000000..9bb3e1e --- /dev/null +++ b/lib/zorder.rb @@ -0,0 +1,12 @@ +class IMICRTS + class ZOrder + base_z = 5 + enum = [ + :GROUND_VEHICLE + ] + + enum.each_with_index do |constant, index| + self.const_set(constant, index + base_z) + end + end +end \ No newline at end of file