Time for action – moving and resetting
We move the terrain inside the move
method.
The
move
method receives as a parameter the amount of movement in thex
axis:void Terrain::move (float xMove) { if (xMove < 0) return; if (_startTerrain) { if (xMove > 0 && _gapSize < 5) _increaseGapTimer += xMove; if (_increaseGapTimer > _increaseGapInterval) { _increaseGapTimer = 0; _gapSize += 1; } } this->setPositionX(this->getPositionX() - xMove); auto block = _blocks.at(0); if (_position.x + block->getWidth() < 0) { auto firstBlock = _blocks.at(0); _blocks.erase(0); _blocks.pushBack(firstBlock); _position.x += block->getWidth(); float width_cnt = this->getWidth() - block->getWidth() - ( _blocks.at(0))->getWidth(); this->initBlock(block); this->addBlocks(width_cnt); } }
The value for
xMove...