Game Development Reference
In-Depth Information
using Microsoft.Xna.Framework;
1
2
3
class TitleMenuState : GameObjectList
{
4
protected Button playButton, optionButton, helpButton;
5
6
7
public TitleMenuState()
{
8
// load the title screen
9
SpriteGameObject title = new SpriteGameObject("Sprites/spr_titlescreen",
10
0, "background");
11
this .Add(title);
12
13
14
// add a play button
playButton = new Button("Sprites/spr_button_play", 1);
15
playButton.Position = new Vector2(415, 540);
16
this .Add(playButton);
17
18
19
// add an options button
optionButton = new Button("Sprites/spr_button_options", 1);
20
optionButton.Position = new Vector2(415, 650);
21
this .Add(optionButton);
22
23
24
// add a help button
helpButton = new Button("Sprites/spr_button_help", 1);
25
helpButton.Position = new Vector2(415, 760);
26
this .Add(helpButton);
27
}
28
29
30
public override void HandleInput(InputHelper inputHelper)
{
31
base .HandleInput(inputHelper);
32
if (playButton.Pressed)
33
PenguinPairs.GameStateManager.SwitchTo("levelMenu");
34
else if (optionButton.Pressed)
35
PenguinPairs.GameStateManager.SwitchTo("optionsMenu");
36
else if (helpButton.Pressed)
37
PenguinPairs.GameStateManager.SwitchTo("helpState");
38
}
39
}
40
Listing 21.2 The class representing the title menu state, consisting of a background, a 'play game'
button, an 'options' button, and a 'help button'
Search WWH ::




Custom Search