Finally, it's time for the last part in our logic.
Inside
GameLayer.cpp
:void GameLayer::update(float dt) { if (!_running) return; if (_player->getPositionY() < -_player->getHeight() || _player->getPositionX() < -_player->getWidth() * 0.5f) { _running = false; }
If the
_player
object is off screen, we stop the game.Now update all the elements, positions and check for collision:
_player->update(dt); _terrain->move(_player->getVector().x); if (_player->getState() != kPlayerDying) _terrain->checkCollision(_player); _player->place();
Move
_gameBatchNode
in relation to the_player
object:if (_player->getNextPosition().y > _screenSize.height * 0.6f) { _gameBatchNode->setPositionY( (_screenSize.height * 0.6f - _player->getNextPosition().y) * 0.8f); } else { _gameBatchNode->setPositionY ( 0 ); }
Make the game more difficult as...