Game Development Reference
In-Depth Information
_ball->radius();
ballVector.y *= -0.8f;
SimpleAudioEngine::getInstance()->playEffect("hit.wav");
}
}
if (ballNextPosition.y < _ball->radius() ) {
if (_ball->getPosition().x < _screenSize.width *
0.5f - GOAL_WIDTH * 0.5f || _ball->getPosition().x >
_screenSize.width * 0.5f + GOAL_WIDTH * 0.5f) {
ballNextPosition.y = _ball->radius();
ballVector.y *= -0.8f;
SimpleAudioEngine::getInstance()->playEffect("hit.wav");
}
}
9. We finally update the ball information, and if the ball has passed through the goal
posts (drum roll):
_ball->setVector(ballVector);
_ball->setNextPosition(ballNextPosition);
//check for goals!
if (ballNextPosition.y < -_ball->radius() * 2) {
this->playerScore(2);
}
if (ballNextPosition.y > _screenSize.height +
_ball->radius() * 2) {
this->playerScore(1);
}
10. We call our helper method to score a point and we finish the update with the
placement of all the elements, now that we know where the nextPosition
value is for each one of the elements in the game:
Search WWH ::




Custom Search