Game Development Reference
In-Depth Information
Listing 10-39. Saving the Continue Status
void SaveContinueStatus(String Handle)
{
SharedPreferences settings = m_Context.getSharedPreferences(Handle, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("CanContinue", m_CanContinue);
// Commit the edits!
editor.commit();
}
The CheckTouch() function must be modified to integrate the game over function. (See Listing 10-40.)
If the user touches the screen, and the state is the game over screen, and the time that has passed
since the game ended is not yet greater or equal to m_GameOverPauseTime , the program execution
returns from the function without processing the user's touch. This ensures that the game over
message will be displayed for at least m_GameOverPauseTime milliseconds.
If the required amount of time has passed, the IsNewHighScore() function is called to check to see
if the player has made a high score that has to be entered into the high score table. If there is a new
high score, the game state is set to GameState.HighScoreEntry , to indicate that the high score entry
menu has to be displayed. If there is no new high score, the main menu must be displayed.
The camera is then reset to its initial position and rotation. The m_CanContinue variable is set to false,
to indicate that this game is now over and cannot be continued later, and SaveContinueStatus() is
called to save the variable.
Listing 10-40. Modifying the CheckTouch() Function
if (m_GameState == GameState.GameOverScreen)
{
long CurTime = System.currentTimeMillis();
long Delay = CurTime - m_GameOverStartTime;
if (Delay < m_GameOverPauseTime)
{
return;
}
// Test for High Score
if (IsNewHighScore())
{
// Go to High Score Entry Screen
m_GameState = GameState.HighScoreEntry;
}
else
{
m_GameState = GameState.MainMenu;
}
ResetCamera();
 
Search WWH ::




Custom Search