Game Development Reference
In-Depth Information
newY = (float)rand()/((float)RAND_MAX/
_screenSize.height * 0.6f) + _screenSize.height *
0.2f;
if (newY > _screenSize.height * 0.9f)
newY = _screenSize.height * 0.9f;
_comet->setPositionY(newY);
_comet->setVisible(true);
_comet->resetSystem();
}
}
if (_comet->isVisible()) {
//collision with comet
if (pow(_comet->getPositionX() -
_rocket->getPositionX(), 2) +
pow(_comet->getPositionY() - _rocket->getPositionY(),
2) <= pow (_rocket->getRadius() , 2)) {
if (_rocket->isVisible()) killPlayer();
}
_comet->setPositionX(_comet->getPositionX() + 50
* dt);
if (_comet->getPositionX() > _screenSize.width *
1.5f) {
_comet->stopSystem();
_comet->setVisible(false);
}
}
3. Next we update _lineContainer , and slowly reduce the opacity of the
_rocket sprite based on the _energy level in _lineContainer :
_lineContainer->update(dt);
_rocket->setOpacity(_lineContainer->getEnergy() *
255);
This will add a visual cue for the player that time is running out as the _rocket
sprite will slowly turn invisible.
4. Run collision with planets:
Search WWH ::




Custom Search