Class: Asteroids::MenuState
- Includes:
- Singleton
- Defined in:
- lib/asteroids/states/menu_state.rb
Instance Method Summary collapse
- #button_down(id) ⇒ Object
- #draw ⇒ Object
-
#initialize ⇒ MenuState
constructor
A new instance of MenuState.
Methods inherited from GameState
#enter, #leave, #needs_redraw?, switch, #update
Constructor Details
#initialize ⇒ MenuState
Returns a new instance of MenuState.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/asteroids/states/menu_state.rb', line 7 def initialize @title = Gosu::Image.from_text($window, "Asteroids", Utils.get_font_path('victor-pixel.ttf'), 100) @background = Gosu::Image.new($window, Utils.get_image_path('background.png'), false) = Menu.new .add_item("New Game", lambda { GameState.switch(PlayState.new) }, true) .add_item("Load Game", lambda { puts 'load game' }, false) .add_item("Exit", lambda { $window.close }, false) end |
Instance Method Details
#button_down(id) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/asteroids/states/menu_state.rb', line 28 def (id) if id == Gosu::KbDown .select_item(:+) end if id == Gosu::KbUp .select_item(:-) end if id == Gosu::KbReturn .confirm end end |
#draw ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/asteroids/states/menu_state.rb', line 19 def draw @background.draw(0, 0, 0) @title.draw( $window.width / 2 - @title.width / 2, $window.height / 5 - @title.height / 5, 10) .draw end |