Game Development Reference
In-Depth Information
Time for action - starting and restarting
the game
Let's add the logic to start and restart the game.
1. Let's write the implementation for resetGame :
void GameLayer::resetGame(void) {
_score = 0;
_energy = 100;
//reset timers and "speeds"
_meteorInterval = 2.5;
_meteorTimer = _meteorInterval * 0.99f;
_meteorSpeed = 10;//in seconds to reach ground
_healthInterval = 20;
_healthTimer = 0;
_healthSpeed = 15;//in seconds to reach ground
_difficultyInterval = 60;
_difficultyTimer = 0;
_running = true;
//reset labels
_energyDisplay->setString(std::to_string((int)
_energy) + "%");
_scoreDisplay->setString(std::to_string((int)
_score));
}
2. Next, add the implementation of stopGame :
void GameLayer::stopGame() {
_running = false;
//stop all actions currently running
Search WWH ::




Custom Search