Let's go back to GameLayer.cpp
and add our game's final touches (pun intended).
First we work on our
onTouchBegan
method:bool GameLayer::onTouchBegan(Touch* touch, Event* event) { if (!_running) { if (_player->getState() == kPlayerDying) { _terrain->reset(); _player->reset(); resetGame(); } return true; }
If we are not running the game and the
_player
object died, we reset the game on touch.Next, if the terrain has not started, insert the following:
if (!_terrain->getStartTerrain()) { _terrain->setStartTerrain ( true ); return true; }
Remember that at first the buildings are all the same height and there are no gaps. Once the player presses the screen, we begin changing that through
setStartTerrain
.We finish with:
if (touch) { if (_player->getState() == kPlayerFalling) { _player->setFloating ( _player->getFloating...