Game Development Reference
In-Depth Information
$window , "Q = Quit, #{ continue_text } N = New Game" ,
30
Gosu . default_font_name, 30 )
31
32 end
33
34 def draw
35
@message . draw(
$window . width / 2 - @message . width / 2 ,
36
$window . height / 2 - @message . height / 2 ,
37
10 )
38
@info . draw(
39
$window . width / 2 - @info . width / 2 ,
40
$window . height / 2 - @info . height / 2 + 200 ,
41
10 )
42
43 end
44
45 def button_down ( id )
46 $window . close if id == Gosu :: KbQ
47 if id == Gosu :: KbC && @play_state
48 GameState . switch( @play_state )
49 end
50 if id == Gosu :: KbN
51 @play_state = PlayState . new
52 GameState . switch( @play_state )
53 end
54 end
55 end
It's a Singleton , so we can always get it with MenuState.instance .
It starts playing menu_music.mp3 when you enter the menu, and stop the music when
you leave it. Instance of Gosu::Song is cached in @@music class variable to save
resources.
We have to know if play is already in progress, so we can add a possibility to go back to the
game. That's why MenuState has @play_state variable, and either allows creating
new PlayState when N key is pressed, or switches to existing @play_state if C key
is pressed.
Here comes the interesting part, implementing the play state.
Search WWH ::




Custom Search