From d8a646621b30b43a9b3d079c701cb6475d882fb4 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 8 Nov 2021 09:13:12 +0100 Subject: [PATCH] Key events --- src/app.rb | 14 +++++++++++++- src/ui/mainmenu.rb | 5 +++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/app.rb b/src/app.rb index 782e18a..e2c15c0 100755 --- a/src/app.rb +++ b/src/app.rb @@ -15,7 +15,7 @@ require_relative "lib/world.rb" require_relative "ui/mainmenu.rb" class Window < Gosu::Window - attr_accessor :caption, :ui, :world, :mainmenu + attr_accessor :caption, :ui, :world, :mainmenu, :key_events attr_reader :width, :height, :fonts def initialize(title, width, height) @@ -23,6 +23,11 @@ class Window < Gosu::Window @width, @height = width, height self.caption = "#{title}| #{width}x#{height}" + @key_events = { + up: [], + down: [] + } + @ui = [] @fonts = { normal: Gosu::Font.new(self, MAIN_FONT, 18), @@ -71,6 +76,11 @@ class Window < Gosu::Window def button_up(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 @world.controller.button_up(id) @@ -79,6 +89,8 @@ class Window < Gosu::Window def button_down(id) super id + print "down: " + p id if( id == BIND_PAUSE ) then @freeze = !@freeze diff --git a/src/ui/mainmenu.rb b/src/ui/mainmenu.rb index f9371ae..ec158c6 100644 --- a/src/ui/mainmenu.rb +++ b/src/ui/mainmenu.rb @@ -4,6 +4,11 @@ end class MainMenu < UI attr_accessor :show, :playbtn, :quitbtn + +# def quit_game +# self.window.close! +# end + def initialize(window, show=false) super window, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 99 @show = show