Book Image

Cocos2d-x by Example: Beginner's Guide

By : Roger Engelbert
Book Image

Cocos2d-x by Example: Beginner's Guide

By: Roger Engelbert

Overview of this book

Table of Contents (19 chapters)
Cocos2d-x by Example Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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...