diff --git a/.gitignore b/.gitignore index 4e18660..3e71846 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ data/settings.json +data/replays/*.replay +data/saves/*.save doc/ .yardoc/ \ No newline at end of file diff --git a/data/replays/.gitkeep b/data/replays/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/data/saves/.gitkeep b/data/saves/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/i-mic-rts.rb b/i-mic-rts.rb index 8c8831e..d43bd12 100755 --- a/i-mic-rts.rb +++ b/i-mic-rts.rb @@ -19,6 +19,7 @@ require_relative "lib/window" require_relative "lib/camera" require_relative "lib/setting" require_relative "lib/team_colors" +require_relative "lib/constants" require_relative "lib/states/boot" require_relative "lib/states/game" @@ -27,7 +28,7 @@ require_relative "lib/states/menus/main_menu" require_relative "lib/states/menus/credits_menu" require_relative "lib/states/menus/settings_menu" require_relative "lib/states/menus/pause_menu" -require_relative "lib/states/menus/solo_play_menu" +require_relative "lib/states/menus/load_menu" require_relative "lib/states/menus/multiplayer_menu" require_relative "lib/states/menus/solo_lobby_menu" require_relative "lib/states/menus/multiplayer_lobby_menu" diff --git a/lib/components/movement.rb b/lib/components/movement.rb index 084dfbb..3bc206a 100644 --- a/lib/components/movement.rb +++ b/lib/components/movement.rb @@ -10,6 +10,8 @@ class IMICRTS follow_path else + return unless @parent.target + rotate_towards(@parent.target) @parent.position -= (@parent.position.xy - @parent.target.xy).normalized * @parent.speed end diff --git a/lib/constants.rb b/lib/constants.rb new file mode 100644 index 0000000..37e4a43 --- /dev/null +++ b/lib/constants.rb @@ -0,0 +1,4 @@ +class IMICRTS + MENU_WIDTH = 350 + MENU_PADDING = 8 +end \ No newline at end of file diff --git a/lib/entity.rb b/lib/entity.rb index ddd123a..ddbab0d 100644 --- a/lib/entity.rb +++ b/lib/entity.rb @@ -99,7 +99,7 @@ class IMICRTS def target=(entity) @target = entity - component(:movement).pathfinder = @director.find_path(player: @player, entity: self, goal: @target) if component(:movement) && @movement == :ground + component(:movement).pathfinder = @director.find_path(player: @player, entity: self, goal: @target) if @target && component(:movement) && @movement == :ground end def hit?(x_or_vector, y = nil) diff --git a/lib/states/game.rb b/lib/states/game.rb index 563589e..32623f7 100644 --- a/lib/states/game.rb +++ b/lib/states/game.rb @@ -34,7 +34,7 @@ class IMICRTS @debug_info = CyberarmEngine::Text.new("", y: 10, z: Float::INFINITY, shadow_color: Gosu::Color.rgba(0, 0, 0, 200)) - @sidebar = stack(width: 350, height: 1.0) do + @sidebar = stack(width: IMICRTS::MENU_WIDTH, height: 1.0, padding: IMICRTS::MENU_PADDING) do background [0x55555555, 0x55666666] label "SIDEBAR", text_size: 78, margin_bottom: 20 diff --git a/lib/states/menus/credits_menu.rb b/lib/states/menus/credits_menu.rb index fd53a7d..ba04dca 100644 --- a/lib/states/menus/credits_menu.rb +++ b/lib/states/menus/credits_menu.rb @@ -3,14 +3,29 @@ class IMICRTS def setup background [0xff7b6ead, 0xff7a0d71, 0xff7a0d71, 0xff7b6ead] - stack(width: 600, height: 1.0) do - background [0xff555555, Gosu::Color::GRAY] + flow(width: 1.0, height: 1.0) do + stack(width: IMICRTS::MENU_WIDTH, height: 1.0, padding: IMICRTS::MENU_PADDING) do + background [0xff555555, Gosu::Color::GRAY] - label "About I-MIC-RTS", text_size: 78, margin: 20 - label "Words go here. More words also go here. Thank you and have a nice day.", text_wrap: :word_wrap + label "Credits", text_size: 78, margin: 20 - button("Back", width: 1.0, margin_top: 20) do - push_state(MainMenu) + licenses = Gosu::LICENSES.lines + preamble = licenses.shift + licenses.shift # remove blank line + + label preamble, text_wrap: :word_wrap + + licenses.each do |l| + name, website, license, license_website = l.strip.split(",") + flow(width: 1.0) do + label name.strip, width: 0.49 + label license.strip, width: 0.49 + end + end + + button("Back", width: 1.0, margin_top: 20) do + push_state(MainMenu) + end end end end diff --git a/lib/states/menus/load_menu.rb b/lib/states/menus/load_menu.rb new file mode 100644 index 0000000..a8c7b28 --- /dev/null +++ b/lib/states/menus/load_menu.rb @@ -0,0 +1,32 @@ +class IMICRTS + class LoadMenu < CyberarmEngine::GuiState + def setup + self.show_cursor = true + + background [0xff7b6ead, 0xff7a0d71, 0xff7a0d71, 0xff7b6ead] + + stack(width: IMICRTS::MENU_WIDTH, height: 1.0, padding: IMICRTS::MENU_PADDING) do + background [0xff555555, Gosu::Color::GRAY] + label "Load", text_size: 78, margin: 20 + + label "Replays" + stack(width: 1.0, height: 0.30) do + ["2020-01-31_16-31-45.replay"].each do |item| + button item, width: 1.0 + end + end + + label "Saves" + stack(width: 1.0, height: 0.30) do + ["2020-01-31_16-31-45.save"].each do |item| + button item, width: 1.0 + end + end + + button("Back", width: 1.0, margin_top: 20) do + pop_state + end + end + end + end +end \ No newline at end of file diff --git a/lib/states/menus/main_menu.rb b/lib/states/menus/main_menu.rb index 8d17ad7..ddd3a9b 100644 --- a/lib/states/menus/main_menu.rb +++ b/lib/states/menus/main_menu.rb @@ -5,10 +5,11 @@ class IMICRTS background [0xff7b6ead, 0xff7a0d71, 0xff7a0d71, 0xff7b6ead] - stack(width: 350, height: 1.0) do + stack(width: IMICRTS::MENU_WIDTH, height: 1.0, padding: IMICRTS::MENU_PADDING) do background [0xff555555, Gosu::Color::GRAY] - label "I-MIC-RTS", text_size: 78, margin: 20 - button("Campaign", width: 1.0) do + label IMICRTS::NAME, text_size: 78, margin: 20 + button("Campaign", width: 1.0, enabled: false) do + push_state(CampaignMenu) end button("Skirmish", width: 1.0) do @@ -20,7 +21,11 @@ class IMICRTS push_state(MultiplayerMenu) end - button("Settings", width: 1.0, margin_top: 20) do + button("Load", width: 1.0, margin_top: 20) do + push_state(LoadMenu) + end + + button("Settings", width: 1.0) do push_state(SettingsMenu) end diff --git a/lib/states/menus/multiplayer_menu.rb b/lib/states/menus/multiplayer_menu.rb index 9c8da0a..27aafbe 100644 --- a/lib/states/menus/multiplayer_menu.rb +++ b/lib/states/menus/multiplayer_menu.rb @@ -3,7 +3,7 @@ class IMICRTS def setup background [0xff7b6ead, 0xff7a0d71, 0xff7a0d71, 0xff7b6ead] - stack(height: 1.0) do + stack(width: IMICRTS::MENU_WIDTH, height: 1.0, padding: IMICRTS::MENU_PADDING) do background [0xff555555, Gosu::Color::GRAY] label "Multiplayer", text_size: 78, margin: 20 diff --git a/lib/states/menus/pause_menu.rb b/lib/states/menus/pause_menu.rb index 5238a06..a8f2acd 100644 --- a/lib/states/menus/pause_menu.rb +++ b/lib/states/menus/pause_menu.rb @@ -1,14 +1,19 @@ class IMICRTS class PauseMenu < CyberarmEngine::GuiState def setup - stack(width: 350) do + stack(width: IMICRTS::MENU_WIDTH, height: 1.0, padding: IMICRTS::MENU_PADDING) do + background [0xff555555, Gosu::Color::GRAY] + label "Paused", text_size: 78, margin: 20 + button "Resume", width: 1.0 do pop_state end + button "Settings", width: 1.0 do push_state(SettingsMenu) end - button "Quit", width: 1.0 do + + button "Quit", width: 1.0, margin_top: 20 do # TODO: Confirm previous_state.director.finalize @@ -25,7 +30,7 @@ class IMICRTS def draw previous_state&.draw - # Gosu.flush + Gosu.flush super end diff --git a/lib/states/menus/settings_menu.rb b/lib/states/menus/settings_menu.rb index 2cffba2..1f587de 100644 --- a/lib/states/menus/settings_menu.rb +++ b/lib/states/menus/settings_menu.rb @@ -3,22 +3,18 @@ class IMICRTS def setup background [0xff7b6ead, 0xff7a0d71, 0xff7a0d71, 0xff7b6ead] - stack(width: 350, height: 1.0) do + stack(width: IMICRTS::MENU_WIDTH, height: 1.0, padding: IMICRTS::MENU_PADDING) do background [0xff555555, Gosu::Color::GRAY] label "Settings", text_size: 78, margin: 20 @skip_intro = check_box "Skip Intro", checked: Setting.enabled?(:skip_intro) - stack(width: 1.0) do - background 0xff030303 - - label "Debug Settings" - @debug_mode = check_box "Debug Mode", checked: Setting.enabled?(:debug_mode) - @debug_info_bar = check_box "Show Debug Info Bar", checked: Setting.enabled?(:debug_info_bar) - @debug_pathfinding = check_box "Debug Pathfinding", checked: Setting.enabled?(:debug_pathfinding) - @debug_pathfinding_allow_diagonal = check_box "Allow Diagonal Paths", checked: Setting.enabled?(:debug_pathfinding_allow_diagonal) - end + label "Debug Settings", background: 0xff030303, width: 1.0, margin_top: 20 + @debug_mode = check_box "Debug Mode", checked: Setting.enabled?(:debug_mode) + @debug_info_bar = check_box "Show Debug Info Bar", checked: Setting.enabled?(:debug_info_bar) + @debug_pathfinding = check_box "Debug Pathfinding", checked: Setting.enabled?(:debug_pathfinding) + @debug_pathfinding_allow_diagonal = check_box "Allow Diagonal Paths", checked: Setting.enabled?(:debug_pathfinding_allow_diagonal) button("Save and Close", width: 1.0, margin_top: 20) do if valid_options? diff --git a/lib/states/menus/solo_lobby_menu.rb b/lib/states/menus/solo_lobby_menu.rb index 17f5e5e..47e7d10 100644 --- a/lib/states/menus/solo_lobby_menu.rb +++ b/lib/states/menus/solo_lobby_menu.rb @@ -3,7 +3,7 @@ class IMICRTS def setup background [0xff7b6ead, 0xff7a0d71, 0xff7a0d71, 0xff7b6ead] - stack(width: 0.5, min_width: 720, height: 1.0) do + stack(width: 0.5, min_width: 720, height: 1.0, padding: IMICRTS::MENU_PADDING) do background [0xff555555, Gosu::Color::GRAY] label "Lobby", text_size: 78, margin: 20 diff --git a/lib/states/menus/solo_play_menu.rb b/lib/states/menus/solo_play_menu.rb deleted file mode 100644 index fa5da9d..0000000 --- a/lib/states/menus/solo_play_menu.rb +++ /dev/null @@ -1,25 +0,0 @@ -class IMICRTS - class SoloPlayMenu < CyberarmEngine::GuiState - def setup - background [0xff7b6ead, 0xff7a0d71, 0xff7a0d71, 0xff7b6ead] - - stack(height: 1.0) do - background [0xff555555, Gosu::Color::GRAY] - - label "Solo Play", text_size: 78, margin: 20 - label "Words go here.\nMore words also go here. Thank you and have a nice day." - - button("Campaign", width: 1.0) do - end - - button("Skirmish", width: 1.0) do - push_state(SoloLobbyMenu) - end - - button("Back", width: 1.0, margin_top: 20) do - push_state(MainMenu) - end - end - end - end -end \ No newline at end of file diff --git a/lib/tools/entity_controller.rb b/lib/tools/entity_controller.rb index 13f4d67..49b3988 100644 --- a/lib/tools/entity_controller.rb +++ b/lib/tools/entity_controller.rb @@ -36,7 +36,7 @@ class IMICRTS ) when Gosu::KB_S - @director.schedule_order(Order::STOP, @player.id) + @director.schedule_order(Order::STOP, @player.id) if @player.selected_entities.size.positive? when Gosu::MS_LEFT unless @game.sidebar.hit?(@game.window.mouse_x, @game.window.mouse_y) diff --git a/lib/window.rb b/lib/window.rb index 21faeeb..b5fa0ac 100644 --- a/lib/window.rb +++ b/lib/window.rb @@ -22,9 +22,9 @@ class IMICRTS end def draw - @cursor.draw(mouse_x, mouse_y, Float::INFINITY) if @show_cursor - super + + @cursor.draw(mouse_x, mouse_y, Float::INFINITY) if @show_cursor end def update