Game Development Reference
In-Depth Information
(player->radius() + _ball->radius() + force) *
cos(angle);
ballNextPosition.y = playerNextPosition.y +
(player->radius() + _ball->radius() + force) *
sin(angle);
SimpleAudioEngine::getInstance()->playEffect("hit.wav");
}
}
7. Next, we will check the collision between the ball and screen sides. If so, we will
move the ball back to the court and play our sound effect here as well:
if (ballNextPosition.x < _ball->radius()) {
ballNextPosition.x = _ball->radius();
ballVector.x *= -0.8f;
SimpleAudioEngine::getInstance()->playEffect("hit.wav");
}
if (ballNextPosition.x > _screenSize.width -
_ball->radius()) {
ballNextPosition.x = _screenSize.width -
_ball->radius();
ballVector.x *= -0.8f;
SimpleAudioEngine::getInstance()->playEffect("hit.wav");
}
8. At the top and bottom sides of the court, we check to see whether the ball has not
moved through one of the goals through our previously defined GOAL_WIDTH
property as follows:
if (ballNextPosition.y > _screenSize.height -
_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 = _screenSize.height -
Search WWH ::




Custom Search