当前位置: 首页>>代码示例>>C++>>正文


C++ Paddle::x方法代码示例

本文整理汇总了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;
    }
开发者ID:onurtemizkan,项目名称:sfml-arcade-games,代码行数:7,代码来源:Arkanoid.cpp

示例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;
}
开发者ID:luckytina,项目名称:cppcon2014,代码行数:8,代码来源:p08.cpp

示例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));
}
开发者ID:SuperV1234,项目名称:itcpp2015,代码行数:14,代码来源:p09.cpp

示例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;
}
开发者ID:OleksanderPasicznyk,项目名称:Tutorials,代码行数:16,代码来源:p6.cpp

示例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;
}
开发者ID:Boza-s6,项目名称:cppcon2014,代码行数:23,代码来源:p05.cpp


注:本文中的Paddle::x方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。