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); } }
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"); }