Game Development Reference
In-Depth Information
Time for action - adding our resets and
kills
We need to add logic to restart our game and to move our pickup star to a new position. But
first, let's kill the player!
1. Inside the killPlayer method, add the following lines:
void GameLayer::killPlayer() {
SimpleAudioEngine::getInstance()->stopBackgroundMusic();
SimpleAudioEngine::getInstance()->stopAllEffects();
SimpleAudioEngine::getInstance()->playEffect("shipBoom.wav");
_boom->setPosition(_rocket->getPosition());
_boom->resetSystem();
_rocket->setVisible(false);
_jet->stopSystem();
_lineContainer->setLineType ( LINE_NONE );
_running = false;
_state = kGameOver;
_gameOver->setVisible(true);
_pauseBtn->setVisible(false);
}
2. Inside resetStar , add the following lines:
void GameLayer::resetStar() {
Point position = _grid[_gridIndex];
_gridIndex++;
if (_gridIndex == _grid.size()) _gridIndex = 0;
//reset star particles
_star->setPosition(position);
_star->setVisible(true);
Search WWH ::




Custom Search