physics
E. Almqvist 3 years ago
parent 5521f78401
commit 9397f953a5
  1. 2
      src/app.rb
  2. 31
      src/lib/ui.rb
  3. 31
      src/ui/mainmenu.rb

@ -12,6 +12,8 @@ require_relative "lib/objects.rb"
require_relative "lib/controller.rb" require_relative "lib/controller.rb"
require_relative "lib/world.rb" require_relative "lib/world.rb"
require_relative "ui/mainmenu.rb"
class Window < Gosu::Window class Window < Gosu::Window
attr_accessor :caption, :ui, :world, :mainmenu attr_accessor :caption, :ui, :world, :mainmenu
attr_reader :width, :height, :fonts attr_reader :width, :height, :fonts

@ -69,6 +69,8 @@ class Button < UI
default: 0xaa_aaaaaa default: 0xaa_aaaaaa
} }
} }
@events = {}
end end
def hover? def hover?
@ -96,32 +98,3 @@ class Button < UI
self.draw_text(self.text, self.font, self.width/2 - self.text_width/2, self.height/2 - self.text_height/2, self.colors[:text][sel]) self.draw_text(self.text, self.font, self.width/2 - self.text_width/2, self.height/2 - self.text_height/2, self.colors[:text][sel])
end end
end end
class MainMenu < UI
attr_accessor :show, :playbtn, :quitbtn
def initialize(window, show=false)
super window, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 99
@show = show
@playbtn = Button.new(self.window, self, "Play", self.window.fonts[:button])
@playbtn.add_event(:onclick, method(:quit_game))
@playbtn.x, @playbtn.y = self.width/2 - @playbtn.width/2, self.height/2 - @playbtn.height/2
@quitbtn = Button.new(self.window, self, "Quit", self.window.fonts[:button])
@quitbtn.x, @quitbtn.y = self.width/2 - @quitbtn.width/2, @quitbtn.height + @playbtn.y + 16
end
def render
if( @show ) then
self.draw_rect(0, 0, self.width, self.height, 0xaa_111015)
titletext = "Hohmann Miner"
titlewidth = self.window.fonts[:title].text_width(titletext)
self.draw_text(titletext, self.window.fonts[:title], self.width/2 - titlewidth/2, self.height/4)
@playbtn.render
@quitbtn.render
end
end
end

@ -0,0 +1,31 @@
def quit_game
puts "QUIT"
end
class MainMenu < UI
attr_accessor :show, :playbtn, :quitbtn
def initialize(window, show=false)
super window, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 99
@show = show
@playbtn = Button.new(self.window, self, "Play", self.window.fonts[:button])
@playbtn.add_event(:onclick, method(:quit_game))
@playbtn.x, @playbtn.y = self.width/2 - @playbtn.width/2, self.height/2 - @playbtn.height/2
@quitbtn = Button.new(self.window, self, "Quit", self.window.fonts[:button])
@quitbtn.x, @quitbtn.y = self.width/2 - @quitbtn.width/2, @quitbtn.height + @playbtn.y + 16
end
def render
if( @show ) then
self.draw_rect(0, 0, self.width, self.height, 0xaa_111015)
titletext = "Hohmann Miner"
titlewidth = self.window.fonts[:title].text_width(titletext)
self.draw_text(titletext, self.window.fonts[:title], self.width/2 - titlewidth/2, self.height/4)
@playbtn.render
@quitbtn.render
end
end
end
Loading…
Cancel
Save