Game Development Reference
In-Depth Information
15 GameState . switch( MenuState . instance)
16 $window . show
In our entry point we also have a small helper which will help loading images and sounds
using Game.media_path .
The rest is obvious: we create GameWindow instance and store it in $window variable, as
discussed before. Then we use GameState.switch) to load MenuState , and show
the game window.
Implementing Menu State
This is how simple MenuState implementation looks like:
03-prototype/states/menu_state.rb
1 require 'singleton'
2 class MenuState < GameState
3
include Singleton
attr_accessor :play_state
4
5
6 def initialize
7
@message = Gosu :: Image . from_text(
$window , "Tanks Prototype" ,
8
Gosu . default_font_name, 100 )
9
10 end
11
12 def enter
13 music . play( true )
14 music . volume = 1
15 end
16
17 def leave
18 music . volume = 0
19 music . stop
20 end
21
22 def music
23
@@music ||= Gosu :: Song . new(
$window , Game . media_path( 'menu_music.mp3' ))
24
25 end
26
27 def update
28
continue_text = @play_state ? "C = Continue, " : ""
@info = Gosu :: Image . from_text(
29
Search WWH ::




Custom Search