Redid menus, stubbed Entity

This commit is contained in:
2019-09-30 20:49:41 -05:00
parent 31d96354f7
commit a44355a871
11 changed files with 214 additions and 112 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 734 B

View File

@@ -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
IMICRTS::Window.new(width: Gosu.screen_width, height: Gosu.screen_height, fullscreen: true).show

13
lib/entity.rb Normal file
View File

@@ -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

18
lib/states/about_menu.rb Normal file
View File

@@ -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

View File

@@ -1,3 +1,4 @@
class IMICRTS
class Boot < CyberarmEngine::GameState
def setup
@title = Gosu::Font.new(56, name: "Noto Sans Display", bold: true)
@@ -74,3 +75,4 @@ class Boot < CyberarmEngine::GameState
@loader.update
end
end
end

28
lib/states/closing.rb Normal file
View File

@@ -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

47
lib/states/game.rb Normal file
View File

@@ -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

View File

@@ -1,53 +1,25 @@
class IMICRTS
class MainMenu < CyberarmEngine::GuiState
def setup
self.show_cursor = true
@container = stack do
background 0xff00aa00
flow do
background [0xff7b6ead, 0xff7a0d71, 0xff7a0d71, 0xff7b6ead]
stack(height: 1.0) do
background Gosu::Color.rgba(50, 50, 50, 200)
button("Play")
button("About")
button("Exit") do
$window.close
end
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"
button("Exit", width: 1.0) do
push_state(Closing)
end
end
end
end
end
$window.width = @container.width
$window.height = @container.height
$window.fullscreen = false
end
end

11
lib/window.rb Normal file
View File

@@ -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

12
lib/zorder.rb Normal file
View File

@@ -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