physics
E. Almqvist 3 years ago
parent 15afad8910
commit d8a646621b
  1. 14
      src/app.rb
  2. 5
      src/ui/mainmenu.rb

@ -15,7 +15,7 @@ require_relative "lib/world.rb"
require_relative "ui/mainmenu.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, :key_events
attr_reader :width, :height, :fonts attr_reader :width, :height, :fonts
def initialize(title, width, height) def initialize(title, width, height)
@ -23,6 +23,11 @@ class Window < Gosu::Window
@width, @height = width, height @width, @height = width, height
self.caption = "#{title}| #{width}x#{height}" self.caption = "#{title}| #{width}x#{height}"
@key_events = {
up: [],
down: []
}
@ui = [] @ui = []
@fonts = { @fonts = {
normal: Gosu::Font.new(self, MAIN_FONT, 18), normal: Gosu::Font.new(self, MAIN_FONT, 18),
@ -71,6 +76,11 @@ class Window < Gosu::Window
def button_up(id) def button_up(id)
super id super id
print "up: "
p id
@key_events[:down].delete(id) # when the key is released: stop holding it
@key_events[:up] << id # append the key event to the queue
if( @world && @world.controller ) then if( @world && @world.controller ) then
@world.controller.button_up(id) @world.controller.button_up(id)
@ -79,6 +89,8 @@ class Window < Gosu::Window
def button_down(id) def button_down(id)
super id super id
print "down: "
p id
if( id == BIND_PAUSE ) then if( id == BIND_PAUSE ) then
@freeze = !@freeze @freeze = !@freeze

@ -4,6 +4,11 @@ end
class MainMenu < UI class MainMenu < UI
attr_accessor :show, :playbtn, :quitbtn attr_accessor :show, :playbtn, :quitbtn
# def quit_game
# self.window.close!
# end
def initialize(window, show=false) def initialize(window, show=false)
super window, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 99 super window, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 99
@show = show @show = show

Loading…
Cancel
Save