Class: Asteroids::MenuState
- Inherits:
-
GameState
show all
- Includes:
- Singleton
- Defined in:
- lib/asteroids/states/menu_state.rb
Instance Method Summary
collapse
Methods inherited from GameState
#enter, #leave, #needs_redraw?, switch, #update
Constructor Details
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 = Menu.new
@menu.add_item("New Game", lambda { GameState.switch(PlayState.new) },
true)
@menu.add_item("Load Game", lambda { puts 'load game' }, false)
@menu.add_item("Exit", lambda { $window.close }, false)
end
|
Instance Method Details
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/asteroids/states/menu_state.rb', line 28
def button_down(id)
if id == Gosu::KbDown
@menu.select_item(:+)
end
if id == Gosu::KbUp
@menu.select_item(:-)
end
if id == Gosu::KbReturn
@menu.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)
@menu.draw
end
|