From a44355a87144d11caec989954f84e86bcf391859 Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Mon, 30 Sep 2019 20:49:41 -0500 Subject: [PATCH] Redid menus, stubbed Entity --- .../images/construction_worker.png | Bin 0 -> 1089 bytes .../vehicles/harvester/images/harvester.png | Bin 0 -> 734 bytes i-mic-rts.rb | 19 ++- lib/entity.rb | 13 ++ lib/states/about_menu.rb | 18 +++ lib/states/boot.rb | 122 +++++++++--------- lib/states/closing.rb | 28 ++++ lib/states/game.rb | 47 +++++++ lib/states/main_menu.rb | 56 ++------ lib/window.rb | 11 ++ lib/zorder.rb | 12 ++ 11 files changed, 214 insertions(+), 112 deletions(-) create mode 100644 assets/vehicles/construction_worker/images/construction_worker.png create mode 100644 assets/vehicles/harvester/images/harvester.png create mode 100644 lib/entity.rb create mode 100644 lib/states/about_menu.rb create mode 100644 lib/states/closing.rb create mode 100644 lib/states/game.rb create mode 100644 lib/window.rb create mode 100644 lib/zorder.rb 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 0000000000000000000000000000000000000000..f6d1a6556a34bcce482f19ae16d732fb0e092e17 GIT binary patch literal 1089 zcmV-H1it%;P)C&{iNxcz46rDH1n2LY8Zlxfyd9@+iaAG^haD*!Atd!U+ zO`9g)IbM88mgGynbaey4J#a40drqG7@bG@m8~DFNEb@2Dfi*x=W&l0WSsa1-W0DOJ{4vd1= z1pzMYtr=Gyb7Jm2(-uWIb&%wHz;Y?Jbf%|F| zC;tE`;KjROef<@Z^#?IcO=T&5AnD4l^lh^o=o?Z1J9SZyG}pp`&2a1&c=s$wp+LZ~ zU*Uzd@IZsTsWKcp0rs|A4(uINx$^=6y@yr)wwV$Tz=I92X(fbDTD8zUU^usPGr;Rd zlm#{ZZ4u*ggK5IEWp5fR95bBWhcNRQZ=s@?Ec7@jxp}{f^^tMZa zZPIq>S|Qjb>1}s#p#SLgbzuK+83)20lAi16Ku?<_+~MFr@GDh#CJotl%8G%er77BP z)ws*(ODPz-C>Z)49T>$QTpj z=X3j+%TWL-s%mnzy2jh74>aZWZ$GmRrOawzs)*m7g#DQ$3|mPU)LM~BCUASa0MrMX z3dqYLl}wkP@nz+*nnMABFFcougDTy!0ZV=C%^iT+N@fmgq{G7YnLJy?;MziLa=7Q0Gu zdGf`20NuS+>OEUz_QHHf0ozN|TQg_#LGRfjb@x^|zks6UB;YLe$$Pw<02~~c7jDUJ zAuvl2I4&VD-ICqq_#LOX*UkI>O8MmT4|ywpi<%1(oW+V7gZI8kB&KH6!97{62*00000NkvXX Hu0mjf=a};- literal 0 HcmV?d00001 diff --git a/assets/vehicles/harvester/images/harvester.png b/assets/vehicles/harvester/images/harvester.png new file mode 100644 index 0000000000000000000000000000000000000000..f524456aa5532f84c218f9913ed2873b266301b8 GIT binary patch literal 734 zcmV<40wMj0P)7?m=g-n?gRvuATx9{J+_!aT)^rNW=BJcGmwmaJYKe$Ym+yvmb#Y%><0@ z1Igp3#|B3)UZY&v=G)t2TA)EF4?nHJGw$A1MK$7l&$sYIMu zB!nahJO>WrJv4+Qw1+9>5~)O-^!HCFN|{t54&Z9XfNkwtl&|?HrLx4UUowS_B5sct zi_|!Is-lohr*JrJc>7AoLSe1457-Pebcvwx4`4DP?HH)%3(yY?14|nDrE2aV@VV8d zdP~p?)L+6gKp(Ih$N}Ch^|@+Jt=87(^T4{6NYky@DwtPcLI_$s1+*!Zkjo0Qz^qoj z=?n-NapeN?*ctPiRXxEF%0l=*1`5GE?Z1Gvm}#b?cN$s@@@7!Bsn7QF7YXIkI%Z>C QlmGw#07*qoM6N<$f~>hgivR!s literal 0 HcmV?d00001 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