Game Development Reference
In-Depth Information
//change height of next block
blockHeight =
_blockHeights[_currentHeightIndex];
//if difference too high, decrease it
if (blockHeight - _lastBlockHeight > 2 &&
_gapSize == 2)
{
blockHeight = 1;
}
} else {
blockHeight = _lastBlockHeight;
}
_currentHeightIndex++;
if (_currentHeightIndex == _blockHeights.size()) {
_currentHeightIndex = 0;
random_shuffle(_blockHeights.begin(),
_blockHeights.end());
}
block->setupBlock (blockWidth, blockHeight, type);
_lastBlockWidth = blockWidth;
_lastBlockHeight = blockHeight;
Notice how we reshuffle the arrays once we are done iterating through them
( random_shuffle ).
We use _lastBlockHeight to apply an extra condition to our terrain. We
don't want the next block to be too tall in relation to the previous building, at least
not in the beginning of the game, which we can determine by checking the value
for _gapSize , which is only increased when the game gets harder.
And if the value from _blockHeights is 0 , we don't change the height of the
new building and use instead the same value from _lastBlockHeight .
5. We finish by updating the count in the current series of buildings to determine
whether we should show a gap next, or not:
Search WWH ::




Custom Search