本文整理汇总了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);
}
}
示例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");
}