Esempio n. 1
0
void AudioDevice::playSound2D(const std::string& soundfile, SoundType type) {
    if ((m_engine != NULL) && ! soundfile.empty()) {
        FileSystem::markFileUsed(soundfile);

        const bool loop = (type == MUSIC);
        ISound* sound = m_engine->play2D(soundfile.c_str(), loop, START_PAUSED, RETURN_REFERENCE);

        switch (type) {
        case MUSIC:
            sound->setVolume(m_musicVolume * MUSIC_VOLUME_CONSTANT);
            if (m_music) {
                // Stop the previous music and replace it with this
                m_music->stop();
                m_music->drop();
            }
            m_music = sound;
            sound->setIsPaused(false);
            break;

        case UI:
            sound->setVolume(m_uiVolume * UI_VOLUME_CONSTANT);
            sound->setIsPaused(false);
            sound->drop();
            break;

        case EFFECT:
            sound->setVolume(m_effectVolume * EFFECT_VOLUME_CONSTANT);
            sound->setPlaybackSpeed(speedAdjust(m_timeScaleAtListener));
            sound->setIsPaused(false);
            sound->drop();
            break;
        }
    }
}
void SoundSystem::Play3D(Sound3D* media){
	if(Instance().CheckSoundPlaying(media)){//if playing
		ISound* temp = Instance().currPlayingLoopedSounds[media];
		if(!temp->getIsPaused()){
			temp->setPlayPosition(0.0f);//set back to beginning
		}
		temp->setIsLooped(false);
		temp->setSoundStopEventReceiver (Instance().sndEndReceiver,media);
		temp->setVolume(media->volume);
		temp->setMinDistance(media->minSoundDist);
		temp->setMaxDistance(FLT_MAX); // max attenuation distance
		temp->setIsPaused(false);
	}else{
		//creates a new sound instance
         ISound* temp = Instance().soundEngine->play3D(media->mySoundSource,vec3df(media->GetSoundPosition()[x],media->GetSoundPosition()[y],media->GetSoundPosition()[z]),false,false,true);
		
		//ISound* temp = Instance().soundEngine->play3D(media->mySoundSource,media->GetPosition(),false,true);
		Instance().currPlayingLoopedSounds.insert(std::pair<Sound*,ISound*>(media,temp));
		temp->setSoundStopEventReceiver(Instance().sndEndReceiver,media);
		temp->setVolume(media->volume);
		temp->setMinDistance(media->minSoundDist);
		temp->setMaxDistance(FLT_MAX); // max attenuation distance
		temp->setIsPaused(false);
		
	}
}
Esempio n. 3
0
void AudioDevice::playSound3D(const std::string& soundfile, const Point3& wsPosition, const Vector3& wsVelocity, const float timeScale) {
    if ((m_engine != NULL) && ! soundfile.empty()) {
        FileSystem::markFileUsed(soundfile);

        ISound* sound = m_engine->play3D(soundfile.c_str(), g3dToirrKlang(wsPosition), 
                                         ! PLAY_LOOPED, START_PAUSED, RETURN_REFERENCE);

        if (sound) {
            // Distance at which the sound plays at "full" volume
            sound->setMinDistance(200.0f);
            sound->setVelocity(g3dToirrKlang(wsVelocity * timeScale));
            sound->setVolume(m_effectVolume * EFFECT_3D_VOLUME_CONSTANT);

            m_active3D.append(sound);

            if (timeScale != 1.0f) {
                sound->setPlaybackSpeed(speedAdjust(m_timeScaleAtListener));
            }

            // Start playing the sound
            sound->setIsPaused(false);

            // Don't drop the reference; we're holding it in m_active3D
        }
    }
}
Esempio n. 4
0
void Game::applyRocketsMoves()
{
	// Fly thier ways
	rockets->fly(timer.delta);
	effects->drawRocketUpEffect(timer.delta);
	effects->drawRocketDownEffect(timer.delta);
	
	// Getting all nodes rockets hited & indecies for rockets
	array<u32> *Findecies, *Eindecies;
	Findecies = new array<u32>();
	Eindecies = new array<u32>();
	array<ISceneNode *> nodes = rockets->checkRockets(Findecies, Eindecies);
	effects->deleteRocketUp(Findecies);
	effects->deleteRocketDown(Eindecies);

	for (u32 i = 0; i < nodes.size(); i++)
	{
		vector3df pos = IDLE_VECTOR;

		// Checking fot fighter damage and death
		if (nodes[i] == fighter->getNode())
		{
			fighter->damage(FIGHTER_DAMAGE);
			if (fighter->isDead())
			{
				if (soundPlay)
				{
					ISound *bang = sound->play2D("sounds/bang.wav", false, true);
					bang->setVolume(0.1f);
					bang->setIsPaused(false);
					bang->drop();
				}
				state = OVER;
				engine->hideCursor(false);
				drop();
				gui->lose(engine->getGUI(), texManager);
				return;
			}
		}

		// Checking for enemies damage and death
		else if (enemies->checkNode(nodes[i], engine->getManager(), &score, sound, soundPlay, &pos))
		{
			state = OVER;
			engine->hideCursor(false);
			drop();
			gui->win(engine->getGUI(), texManager);
			return;
		}

		if (pos != vector3df(IDLE_VECTOR))
			effects->addDeath(engine->getManager(), texManager->getEffectsTexture()[0], pos);
	}

	// Refrashing score and health
	gui->setScore(score);
	if (!fighter->isDead())
		gui->setHealth(fighter->getHealth());
}
void SoundSystem::Play2DLooped(Sound2D* media){

	if(Instance().CheckSoundPlaying(media)){//if currently playing
		ISound* temp =Instance().currPlayingLoopedSounds[media]; 
		if(!temp->getIsPaused()){//if not paused... start from beginning
			temp->setPlayPosition(0.0f);//set back to beginning
		}
		temp->setIsLooped(true);
		temp->setSoundStopEventReceiver (Instance().sndEndedUsrReceiver,media);
		temp->setVolume(media->volume);
		temp->setIsPaused(false);
	}else{
		//creates a new sound instance
		ISound* temp = Instance().soundEngine->play2D(media->mySoundSource,true,false,true);
		Instance().currPlayingLoopedSounds.insert(std::pair<Sound*,ISound*>(media,temp));
		temp->setSoundStopEventReceiver(Instance().sndEndedUsrReceiver,media);
		temp->setVolume(media->volume);
		temp->setIsPaused(false);
	}

}
Esempio n. 6
0
void Entity::Knockback(Vector3 dir)
{
	kbVelocity.x += dir.x;
	if (velocity.y <= 0)
		velocity.y += 5;
	kbVelocity.z += dir.z;

	vector<char*> soundFileName;

	if (entityID == HORSE)
	{
		soundFileName.push_back("Assets/Media/Damage/horseCry1.mp3");
		soundFileName.push_back("Assets/Media/Damage/horseCry2.mp3");
		soundFileName.push_back("Assets/Media/Damage/horseCry3.mp3");
		soundFileName.push_back("Assets/Media/Damage/horseCry4.mp3");
	}
	//else if (entityID == SENTRY || entityID == ENEMY_2 || entityID == ENEMY_3)
	//{
	//	// Enemy Kenna Hit Sound
	//	soundFileName.push_back("Assets/Media/Damage/enemyCry1.mp3");
	//	soundFileName.push_back("Assets/Media/Damage/enemyCry2.mp3");
	//	soundFileName.push_back("Assets/Media/Damage/enemyCry3.mp3");
	//}
	else if (entityID == WOLF)
	{
		// Wolf Kenna Hit Sound
		soundFileName.push_back("Assets/Media/Damage/wolfCry1.mp3");
		soundFileName.push_back("Assets/Media/Damage/wolfCry2.mp3");
		soundFileName.push_back("Assets/Media/Damage/wolfCry3.mp3");
	}
	else
	{
		soundFileName.push_back("Assets/Media/Damage/hit1.mp3");
		soundFileName.push_back("Assets/Media/Damage/hit2.mp3");
		soundFileName.push_back("Assets/Media/Damage/hit3.mp3");
	}

	ISound* sound = engine->play3D(soundFileName[rand() % soundFileName.size()], vec3df(position.x, position.y, position.z), false, true);
	if (sound)
	{
		sound->setVolume(1.f);
		sound->setIsPaused(false);
	}

	health -= dir.LengthSquared() * 0.01f;
	if (health < 1)
		health = 0;
}