Ejemplo n.º 1
0
void solvePaddleBallCollision(const Paddle& mPaddle, Ball& mBall) noexcept
{
    if(!isIntersecting(mPaddle, mBall)) return;

    auto newY(mPaddle.top() - mBall.shape.getRadius() * 2.f);
    mBall.shape.setPosition(mBall.x(), newY);

    auto paddleBallDiff(mBall.x() - mPaddle.x());
    auto posFactor(paddleBallDiff / mPaddle.width());
    auto velFactor(mPaddle.velocity.x * 0.05f);

    sf::Vector2f collisionVec{posFactor + velFactor, -2.f};
    mBall.velocity = getReflected(mBall.velocity, getNormalized(collisionVec));
}
Ejemplo n.º 2
0
//LBRT order
bool collided(Ball ball, Paddle paddle){
    if(paddle.top() < ball.bottom() || paddle.bottom() > ball.top() || paddle.left() > ball.right() || paddle.right() < ball.left()){
        return false;
    }
    return true;
}