Exemplo n.º 1
0
void Audio::playSFX(const std::string &filename, bool relative, const cml::vector2f &pos, float attenuation, float min_dist)
{
    if(sounds.empty())
        for(int i = 0; i < 32; i++)
        {
            SoundPtr s(new sf::Sound());
            s->SetVolume(60.0f);
            sounds.push_back(s);
        }


    SoundPtr s;

    for(unsigned int i = 0; i < sounds.size(); i++)
        if(sounds[i]->GetStatus() == sf::Sound::Stopped)
            s = sounds[i];

    if(!s)
    {
        warning("too many sounds");
        return;
    }

    SoundBufferPtr sb = getSoundBuffer(filename);
    s->SetRelativeToListener(relative);
    s->SetPosition(pos[0], pos[1], 0.0f);
    s->SetAttenuation(attenuation);
    s->SetMinDistance(min_dist);
    s->SetBuffer(*(sb.get()));
    s->Play();
}
Exemplo n.º 2
0
/** 
 * Initializes the bee's attributes 
 * 
 * 
 * @return bool
 */
bool Bee::DoExtraInits()
{
	if (!GameCharacter::DoExtraInits())
	{
		return false;
	}

	// add a health attribute
	HealthAttributePtr health = NiNew HealthAttribute(this);
	m_fMaxHealth = ConfigurationManager::Get()->bee_initialHealth;
	health->Reset(m_fMaxHealth);
	AddAttribute(GameCharacter::ATTR_HEALTH, (CharacterAttribute*)health);
	// add an armor attribute
	AddAttribute(GameCharacter::ATTR_ARMOR, NiNew ArmorAttribute(this));
	// add a damage attribute
	DamageAttribute* dmg = NiNew DamageAttribute(this);
	dmg->Reset(ConfigurationManager::Get()->bee_damage);
	AddAttribute(GameCharacter::ATTR_DAMAGE, dmg);
	// add an FSMBeeAIControl
	AddAttribute(GameCharacter::ATTR_CONTROLLER, NiNew FSMBeeAIControl(this));
	// set initial position
	m_pActor->setGlobalPosition(GameManager::Get()->
		GetQueen()->GetActor()->getGlobalPosition() - NxVec3(50.0, 0.0, 0.0));

	SoundPtr sound = ResourceManager::Get()->GetSound(
		ResourceManager::RES_SOUND_BEE, this);
	if (sound)
	{
		AddAttribute(GameCharacter::ATTR_SOUND_DEFAULT, (CharacterAttribute*)sound);
		sound->Play();
	}

	AddAttribute(GameCharacter::ATTR_SOUND_1, (CharacterAttribute*) ResourceManager::Get()->GetSound(
		ResourceManager::RES_SOUND_BEE_AWAITING, this));

	AddAttribute(GameCharacter::ATTR_SOUND_2, (CharacterAttribute*) ResourceManager::Get()->GetSound(
		ResourceManager::RES_SOUND_BEE_DYING, this));

	// set dampings
	m_pActor->setLinearDamping(8.0f);
	m_pActor->setAngularDamping(8.0f);

	
	

	return true;
}