Game Development Reference
In-Depth Information
}
_scoreDisplay->setString(std::to_string(_score));
}
2. If _shockwave is visible, we check the distance between it and each sprite in
_fallingObjects vector. If we hit any meteors, we increase the value of the
_shockwaveHits property so we can award the player for multiple hits. Next
we move the clouds:
//move clouds
for (auto sprite : _clouds) {
sprite->setPositionX(sprite->getPositionX() + dt *
20);
if (sprite->getPositionX() > _screenSize.width +
sprite->getBoundingBox().size.width * 0.5f)
sprite->setPositionX(-sprite->getBoundingBox().size.width
* 0.5f);
}
3. I chose not to use a MoveTo action for the clouds to show you the amount of
code that can be replaced by a simple action. If not for Cocos2d-x actions, we
would have to implement logic to move, rotate, swing, scale, and explode all our
sprites!
4. And finally:
if (_bomb->isVisible()) {
if (_bomb->getScale() > 0.3f) {
if (_bomb->getOpacity() != 255)
_bomb->setOpacity(255);
}
}
5. We give the player an extra visual cue to when a bomb is ready to explode by
changing its opacity.
Search WWH ::




Custom Search