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


C++ Shot::createBody方法代码示例

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


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

示例1: if

Shot::Shot(int id, float px, float py, b2Vec2 force, int limit)
{
    name = "shot";
    type = id;

    this->getBodyFixture()->filter.maskBits = FilterShots | FilterWalls | FilterNormal | FilterEnemy | FilterObjects;
    this->getBodyFixture()->filter.categoryBits= FilterShots;

    if(id == 1)
    {
        this->setTexture(TextureManager::TextureControl.get("boulder_8"));
        this->getSprite()->setOrigin(4,4);
        this->m_bodyCircleShape.m_radius = 4/pixelsPerMeter;

        this->getBodyDef()->position.Set(
                    px,
                    py
                    );
        this->getBodyDef()->type = b2_dynamicBody;
        this->getBodyFixture()->friction = 0.5f;
        this->getBodyFixture()->restitution = 0.4f;
        this->getBodyFixture()->density = 2.f;

        this->m_bodyDef.fixedRotation = false;
        this->m_bodyDef.angularDamping = 2.5f;

        Engine::bodylist.push_back(this);
    }
    else if(id == 2)
    {
        this->setTexture(TextureManager::TextureControl.get("boulder_8"));
        this->getSprite()->setOrigin(4,4);
        this->m_bodyCircleShape.m_radius = 4/pixelsPerMeter;

        this->getBodyDef()->position.Set(
                    px-2,
                    0
                    );
        this->getBodyDef()->type = b2_dynamicBody;
        this->getBodyFixture()->friction = 0.5f;
        this->getBodyFixture()->restitution = 0.4f;
        this->getBodyFixture()->density = 2.f;
        this->m_bodyDef.fixedRotation = false;
        this->m_bodyDef.angularDamping = 2.5f;

        if(limit < 8){
            Shot* shot = new Shot(2, px, py, force, limit+1);
            shot->getBodyFixture()->filter.groupIndex = 1;
            shot->createBody(*Engine::world, true);

            force.x *= shot->getBody()->GetMass();
            force.y *= shot->getBody()->GetMass();
            shot->getBody()->ApplyLinearImpulse(force ,shot->getBody()->GetWorldCenter(),true);
        }

        Engine::bodylist.push_back(this);
    }
}
开发者ID:GustJc,项目名称:PhysicsRPG,代码行数:58,代码来源:Shot.cpp

示例2: atira

void PlayerEntity::atira()
{
    //Arrow
    float powerX = shot_power*cos(angle*M_PI/180.f);
    float powerY = shot_power*sin(angle*M_PI/180.f);


    if(selectedShot <= 2) {
        Shot* shot = new Shot(selectedShot,
                              (this->m_animation.getSprite().getPosition().x)/pixelsPerMeter,
                              (this->m_animation.getSprite().getPosition().y)/pixelsPerMeter,
                              b2Vec2( powerX/pixelsPerMeter,
                                      powerY/pixelsPerMeter) );
        shot->createBody(*Engine::world, true);

        shot->getBody()->ApplyLinearImpulse(b2Vec2( shot->getBody()->GetMass()*powerX/pixelsPerMeter,
                                                    shot->getBody()->GetMass()*powerY/pixelsPerMeter  ),shot->getBody()->GetWorldCenter(),true);

    }else
    {
        ShotArrow* shot = new ShotArrow(selectedShot,
                              (this->m_animation.getSprite().getPosition().x)/pixelsPerMeter,
                              (this->m_animation.getSprite().getPosition().y)/pixelsPerMeter,
                              b2Vec2( powerX/pixelsPerMeter,
                                      powerY/pixelsPerMeter) );
        shot->createBody(*Engine::world);
        shot->getBody()->SetAngularDamping( 3 );

        shot->getBody()->ApplyLinearImpulse(b2Vec2( shot->getBody()->GetMass()*powerX/pixelsPerMeter,
                                                    shot->getBody()->GetMass()*powerY/pixelsPerMeter  ),shot->getBody()->GetWorldCenter(),true);
    }
    //Sfx
    if(selectedShot == 2)
        Engine::EngineControl.playSfx("data/music/sfx/shot1.wav");
    else
        Engine::EngineControl.playSfx("data/music/sfx/shot3.wav");
}
开发者ID:GustJc,项目名称:PhysicsRPG,代码行数:37,代码来源:PlayerEntity.cpp


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