Game Development Reference
In-Depth Information
private void OnButtonPress()
{
_buttons[_currentFocus].OnPress();
}
Run the code and use the keyboard or gamepad to navigate the menu. Pressing
the exit button will exit the game, but pressing the start button will currently do
nothing. The start button needs to change the state to the inner game state. This
means that StartMenuState needs access to the state system.
private void InitializeGameState()
{
_system.AddState("start_menu", new StartMenuState(_titleFont,
_generalFont, _input, _system));
The StartMenuState constructor will also need to be modified, and it will
keep a reference to the state system.
StateSystem _system;
public StartMenuState(Engine.Font titleFont, Engine.Font generalFont,
Input input, StateSystem system)
{
_system ¼ system;
This can be used by the start button to change states when it is pressed. The start
button is set up in the InitializeMenu method and needs to be modified
like so.
Button startGame ¼ new Button(
delegate(object o, EventArgs e)
{
_system.ChangeState("inner_game");
},
new Text("Start", _generalFont));
The inner_game state doesn't exist yet but that's what we'll develop next. For a
first pass, the start menu is now complete. Running the program will produce
something similar to Figure 10.5.
Subsequent passes can change this menu as needed, adding more animation,
demo modes, or whatever you like!
 
Search WWH ::




Custom Search