Game Development Reference
In-Depth Information
Time for action - updating the game
We already have the code that updates the countdowns inside the update. If it's time to add
a meteor or a health pack we do it. If it's time to make the game more difficult to play, we
do that too.
Note
It is possible to use an action for these timers: a Sequence action with a Delay action
object and a callback. But there are advantages to using these countdowns. It's easier to re-
set them and to change them, and we can take them right into our main loop.
So it's time to add our main loop:
1. What we need to do is check for collisions. So add the following code:
if (_shockWave->isVisible()) {
count = (int) _fallingObjects.size();
for (i = count-1; i >= 0; i--) {
auto sprite = _fallingObjects.at(i);
diffx = _shockWave->getPositionX() -
sprite->getPositionX();
diffy = _shockWave->getPositionY() -
sprite->getPositionY();
if (pow(diffx, 2) + pow(diffy, 2) <=
pow(_shockWave->getBoundingBox().size.width * 0.5f,
2)) {
sprite->stopAllActions();
sprite->runAction( _explosion->clone());
SimpleAudioEngine::getInstance()->playEffect("boom.wav");
if (sprite->getTag() == kSpriteMeteor) {
_shockwaveHits++;
_score += _shockwaveHits * 13 + _shockwaveHits *
2;
}
//play sound
_fallingObjects.erase(i);
}
Search WWH ::




Custom Search