Class: Nimo::GameWindow
- Defined in:
- lib/nimo/game_window.rb
Overview
Represents a game instance and provides access to the game screen and screen transition. It is an extension of Gosu::Window, thus implementing the update, draw and button_down hooks.
Instance Attribute Summary collapse
-
#current_screen ⇒ Object
readonly
Returns the value of attribute current_screen.
Instance Method Summary collapse
- #add_screen(name, screen) ⇒ Object
- #button_down(id) ⇒ Object
- #close_menu ⇒ Object
- #draw ⇒ Object
-
#go_to(screen_name) ⇒ Object
Switch to a Screen registered with the
screen_name, notifying listeners of the :on_enter event. -
#initialize(name, width, height) ⇒ GameWindow
constructor
A new instance of GameWindow.
-
#open_menu(screen_name) ⇒ Object
Open a Screen registered with the
screen_nameas a menu. -
#update ⇒ Object
:section: Gosu::Window hooks.
Constructor Details
#initialize(name, width, height) ⇒ GameWindow
Returns a new instance of GameWindow.
10 11 12 13 14 15 16 |
# File 'lib/nimo/game_window.rb', line 10 def initialize(name, width, height) super(width, height, false) self.caption = name @screens = {} @background_screens = [] end |
Instance Attribute Details
#current_screen ⇒ Object (readonly)
Returns the value of attribute current_screen.
8 9 10 |
# File 'lib/nimo/game_window.rb', line 8 def current_screen @current_screen end |
Instance Method Details
#add_screen(name, screen) ⇒ Object
18 19 20 21 |
# File 'lib/nimo/game_window.rb', line 18 def add_screen(name, screen) @screens[name] = screen go_to(name) if @screens.size == 1 end |
#button_down(id) ⇒ Object
53 54 55 |
# File 'lib/nimo/game_window.rb', line 53 def (id) @current_screen.(id) end |
#close_menu ⇒ Object
38 39 40 |
# File 'lib/nimo/game_window.rb', line 38 def @current_screen = @background_screens.pop end |
#draw ⇒ Object
48 49 50 51 |
# File 'lib/nimo/game_window.rb', line 48 def draw @background_screens.each { |screen| screen.draw } @current_screen.draw end |
#go_to(screen_name) ⇒ Object
Switch to a Screen registered with the screen_name, notifying listeners of the :on_enter event.
25 26 27 28 29 |
# File 'lib/nimo/game_window.rb', line 25 def go_to(screen_name) raise "There is no screen named #{screen_name}" unless @screens.has_key? screen_name @current_screen = @screens[screen_name] @current_screen.notify(:on_enter) end |
#open_menu(screen_name) ⇒ Object
Open a Screen registered with the screen_name as a menu. To dismiss the menu, use close_menu.
33 34 35 36 |
# File 'lib/nimo/game_window.rb', line 33 def (screen_name) @background_screens << @current_screen go_to(screen_name) end |
#update ⇒ Object
:section: Gosu::Window hooks
44 45 46 |
# File 'lib/nimo/game_window.rb', line 44 def update @current_screen.update end |