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


C++ Vector2::Equals方法代码示例

本文整理汇总了C++中Vector2::Equals方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector2::Equals方法的具体用法?C++ Vector2::Equals怎么用?C++ Vector2::Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector2的用法示例。


在下文中一共展示了Vector2::Equals方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

void Character2D::Update(float timeStep)
{
    // Handle wounded/killed states
    if (killed_)
        return;

    if (wounded_)
    {
        HandleWoundedState(timeStep);
        return;
    }

    // Set temporary variables
    auto* input = GetSubsystem<Input>();
    auto* body = GetComponent<RigidBody2D>();
    auto* animatedSprite = GetComponent<AnimatedSprite2D>();
    bool onGround = false;
    bool jump = false;

    // Collision detection (AABB query)
    Vector2 characterHalfSize = Vector2(0.16f, 0.16f);
    auto* physicsWorld = GetScene()->GetComponent<PhysicsWorld2D>();
    PODVector<RigidBody2D*> collidingBodies;
    physicsWorld->GetRigidBodies(collidingBodies, Rect(node_->GetWorldPosition2D() - characterHalfSize - Vector2(0.0f, 0.1f), node_->GetWorldPosition2D() + characterHalfSize));

    if (collidingBodies.Size() > 1 && !isClimbing_)
        onGround = true;

    // Set direction
    Vector2 moveDir = Vector2::ZERO; // Reset

    if (input->GetKeyDown(KEY_A) || input->GetKeyDown(KEY_LEFT))
    {
        moveDir = moveDir + Vector2::LEFT;
        animatedSprite->SetFlipX(false); // Flip sprite (reset to default play on the X axis)
    }
    if (input->GetKeyDown(KEY_D) || input->GetKeyDown(KEY_RIGHT))
    {
        moveDir = moveDir + Vector2::RIGHT;
        animatedSprite->SetFlipX(true); // Flip sprite (flip animation on the X axis)
    }

    // Jump
    if ((onGround || aboveClimbable_) && (input->GetKeyPress(KEY_W) || input->GetKeyPress(KEY_UP)))
        jump = true;

    // Climb
    if (isClimbing_)
    {
        if (!aboveClimbable_ && (input->GetKeyDown(KEY_UP) || input->GetKeyDown(KEY_W)))
            moveDir = moveDir + Vector2(0.0f, 1.0f);

        if (input->GetKeyDown(KEY_DOWN) || input->GetKeyDown(KEY_S))
            moveDir = moveDir + Vector2(0.0f, -1.0f);
    }

    // Move
    if (!moveDir.Equals(Vector2::ZERO) || jump)
    {
        if (onSlope_)
            body->ApplyForceToCenter(moveDir * MOVE_SPEED / 2, true); // When climbing a slope, apply force (todo: replace by setting linear velocity to zero when will work)
        else
            node_->Translate(Vector3(moveDir.x_, moveDir.y_, 0) * timeStep * 1.8f);
        if (jump)
            body->ApplyLinearImpulse(Vector2(0.0f, 0.17f) * MOVE_SPEED, body->GetMassCenter(), true);
    }

    // Animate
    if (input->GetKeyDown(KEY_SPACE))
    {
        if (animatedSprite->GetAnimation() != "attack")
        {
            animatedSprite->SetAnimation("attack", LM_FORCE_LOOPED);
            animatedSprite->SetSpeed(1.5f);
        }
    }
    else if (!moveDir.Equals(Vector2::ZERO))
    {
        if (animatedSprite->GetAnimation() != "run")
            animatedSprite->SetAnimation("run");
    }
    else if (animatedSprite->GetAnimation() != "idle")
    {
        animatedSprite->SetAnimation("idle");
    }
}
开发者ID:1vanK,项目名称:Urho3D,代码行数:86,代码来源:Character2D.cpp


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