Time for action – starting and restarting the game
Let's add the logic to start and restart the game.
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)); }
Next, add the implementation of
stopGame
:void GameLayer::stopGame() { _running = false; //stop all actions currently running int i; int count = (int) _fallingObjects.size(); for (i = count-1; i >= 0; i--) { auto sprite = _fallingObjects...