Class: MenuState

Inherits:
GameState show all
Includes:
Singleton
Defined in:
lib/game_states/menu_state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from GameState

#needs_redraw?, switch

Constructor Details

#initializeMenuState

Returns a new instance of MenuState.



6
7
8
9
10
# File 'lib/game_states/menu_state.rb', line 6

def initialize
  @message = Gosu::Image.from_text(
    $window, "Tank Island",
    Utils.title_font, 60)
end

Instance Attribute Details

#play_stateObject

Returns the value of attribute play_state.



4
5
6
# File 'lib/game_states/menu_state.rb', line 4

def play_state
  @play_state
end

Instance Method Details

#button_down(id) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/game_states/menu_state.rb', line 46

def button_down(id)
  $window.close if id == Gosu::KbQ
  if id == Gosu::KbC && @play_state
    GameState.switch(@play_state)
  end
  if id == Gosu::KbN
    @play_state = PlayState.new
    GameState.switch(@play_state)
  end
  if id == Gosu::KbD
    @play_state = DemoState.new
    GameState.switch(@play_state)
  end
end

#drawObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/game_states/menu_state.rb', line 35

def draw
  @message.draw(
    $window.width / 2 - @message.width / 2,
    $window.height / 2 - @message.height / 2,
    10)
  @info.draw(
    $window.width / 2 - @info.width / 2,
    $window.height / 2 - @info.height / 2 + 100,
    10)
end

#enterObject



12
13
14
15
# File 'lib/game_states/menu_state.rb', line 12

def enter
  music.play(true)
  music.volume = 1
end

#leaveObject



17
18
19
20
# File 'lib/game_states/menu_state.rb', line 17

def leave
  music.volume = 0
  music.stop
end

#musicObject



22
23
24
25
# File 'lib/game_states/menu_state.rb', line 22

def music
  @@music ||= Gosu::Song.new(
    $window, Utils.media_path('menu_music.ogg'))
end

#updateObject



27
28
29
30
31
32
33
# File 'lib/game_states/menu_state.rb', line 27

def update
  text = "Q: Quit\nN: New Game\nD: Demo"
  text << "\nC: Continue" if @play_state
  @info = Gosu::Image.from_text(
    $window, text,
    Utils.main_font, 30)
end