本文整理汇总了C++中Paddle::x方法的典型用法代码示例。如果您正苦于以下问题:C++ Paddle::x方法的具体用法?C++ Paddle::x怎么用?C++ Paddle::x使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Paddle
的用法示例。
在下文中一共展示了Paddle::x方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testCollision
void testCollision(Paddle& mPaddle, Ball& mBall) {
if(!isIntersecting(mPaddle, mBall)) return;
mBall.velocity.y = -ballVelocity;
if(mBall.x() < mPaddle.x()) mBall.velocity.x = -ballVelocity;
else mBall.velocity.x = ballVelocity;
}
示例2: solvePaddleBallCollision
void solvePaddleBallCollision(const Paddle& mPaddle, Ball& mBall) noexcept
{
if(!isIntersecting(mPaddle, mBall)) return;
mBall.velocity.y = -Ball::defVelocity;
mBall.velocity.x = mBall.x() < mPaddle.x() ?
-Ball::defVelocity : Ball::defVelocity;
}
示例3: solvePaddleBallCollision
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));
}
示例4: testCollision
// Let's define a function that deals with paddle/ball collision.
void testCollision(Paddle& mPaddle, Ball& mBall)
{
// If there's no intersection, get out of the function.
if(!isIntersecting(mPaddle, mBall)) return;
// Otherwise let's "push" the ball upwards.
mBall.velocity.y = -ballVelocity;
// And let's direct it dependently on the position where the
// paddle was hit.
if(mBall.x() < mPaddle.x())
mBall.velocity.x = -ballVelocity;
else
mBall.velocity.x = ballVelocity;
}
示例5: solvePaddleBallCollision
// Now, let's also define a function that will executed every game
// frame. This function will check if a paddle and a ball are
// colliding, and if they are it will resolve the collision by
// making the ball go upwards and in the direction opposite to the
// collision.
void solvePaddleBallCollision(const Paddle& mPaddle, Ball& mBall) noexcept
{
// If there's no intersection, exit the function.
if(!isIntersecting(mPaddle, mBall)) return;
// Otherwise let's "push" the ball upwards.
mBall.velocity.y = -Ball::defVelocity;
// And let's direct it dependently on the position where the
// paddle was hit.
// If the ball's center was to the left of the paddle's center,
// the ball will move towards the left. Otherwise, it will move
// towards the right.
// {Info: ball vs paddle collision}
mBall.velocity.x =
mBall.x() < mPaddle.x() ? -Ball::defVelocity : Ball::defVelocity;
}