Game Development Reference
In-Depth Information
Listing 9-4. The Menu States
enum MenuStates
{
None,
NewGame,
ContinueCurrentGame,
HighScoreTable,
Copyright
}
The
m_NewGameItem
variable holds a reference to a menu item that the user touches, if he or she
wants to start a new game.
MenuItem m_NewGameItem;
The
m_ContinueGameItem
variable holds a reference to a menu item that the user touches if he or she
wants to continue the last saved game.
MenuItem m_ContinueGameItem;
The
m_HighScoresItem
variable holds a reference to a menu item that the user touches if he or she
wants to view the high score table.
MenuItem m_HighScoresItem;
The
m_CopyRightItem
variable holds a reference to a menu item that is used in debugging the high
score entry system.
MenuItem m_CopyRightItem;
The MainMenu constructor initializes the MainMenu class by assigning objects to each of the menu
items in the main menu. (See Listing 9-5.)
Listing 9-5. The MainMenu Constructor
MainMenu(MenuItem NewGameItem,MenuItem ContinueGameItem,MenuItem HighScoresItem,MenuItem
CopyRightItem)
{
m_NewGameItem = NewGameItem;
m_ContinueGameItem = ContinueGameItem;
m_HighScoresItem = HighScoresItem;
m_CopyRightItem = CopyRightItem;
}
The
GetMainMenuStatus()
function tests the main menu items to see if any has been touched at the
screen location (
TouchX
,
TouchY
). Each menu item button is tested to see if it has been touched by
calling the
Touched()
function on that button. The button type that is touched is returned or None is
returned if no menu buttons have been touched. (See Listing 9-6.)