コード例 #1
0
void CCompChoppyThrower::ReceiveMessage(SMessage &msg) {
	if (msg.m_type == EMT_SHOOT && m_lastShot >= GetCooldown()) {
		SShootMsg &shootMsg = static_cast<SShootMsg &>(msg);
		if (shootMsg.GetWeaponId() == GetId()) {
			SGetWorldMsg worldMsg;
			m_owner->ReceiveMessage(worldMsg);
			CWorld * world = worldMsg.GetWorld();
			SGetRotMsg rotMsg;
			m_owner->ReceiveMessage(rotMsg);
			SGetPosMsg posMsg;
			m_owner->ReceiveMessage(posMsg);
			SGetEnergyMsg getEnergyMsg;
			m_owner->ReceiveMessage(getEnergyMsg);
			if (rotMsg.Modified() && getEnergyMsg.Modified() &&
				getEnergyMsg.GetEnergy() - GetEnergyConsumed() > 0) {
				world->AddEntity(world->GetEntitiesFactory().SpawnEntity(
					new SBotParams(m_owner->GetSide(), GetImg(),
						posMsg.GetX(), posMsg.GetY(), m_botLifeTime, GetDamage(),
						m_speed)));
				SUpdateEnergyMsg updateEnergyMsg(-GetEnergyConsumed());
				m_owner->ReceiveMessage(updateEnergyMsg);
				m_lastShot = 0;
				AudioBuffer * buffer = new AudioBuffer("data/sounds/fusion_blaster_shoot.wav");
				AudioSource * shootAudio = new AudioSource(buffer);
				shootAudio->Play();
			}
		}
	}
}
コード例 #2
0
ファイル: Triggerable.cpp プロジェクト: VajraFramework/Vajra
void Triggerable::toggleState() {
	if (this->isToggled) {
		AudioSource* audioSource = this->GetObject()->GetComponent<AudioSource>();
		if (audioSource != nullptr) {
			audioSource->Play("triggerOff");
		}

		this->onSwitchToggled(false);
		this->onSwitchDeactivated();
	}
	else {
		AudioSource* audioSource = this->GetObject()->GetComponent<AudioSource>();
		if (audioSource != nullptr) {
			audioSource->Play("triggerOn");
		}

		this->onSwitchToggled(true);
		this->onSwitchActivated();
	}
	this->isToggled = !this->isToggled;
}
コード例 #3
0
	void	Execute( void )  {
		ogst::unique_lock<ogst::mutex> lock(emitter->mutex);
		if ( emitter->IsValidChannel( channel ) ) {
			AudioSource *source = emitter->sndChannels[channel];
			if ( source == OG_NULL )
				source = audioSystemObject.audioThread->FindFreeAudioSource();

			if ( source ) {
				if ( source->Play( emitter, channel, sound, allowLoop ) ) {
					emitter->sndChannels[channel] = source;
					emitter->sndChannels[channel]->OnUpdate( &emitter->details );
				}
				return;
			}
			User::Warning("No more free sound Sources!");
		}
	}
コード例 #4
0
ファイル: main.cpp プロジェクト: Vonflaken/2d-engine
int main(int argc, char* argv[])
{
	Screen & screen = Screen::Instance();
	const Renderer & renderer = Renderer::Instance();
	ResourceManager & resourceManager = ResourceManager::Instance();

	screen.Open(800, 600, false);

	// Práctica_1 de Programación de Audio

	AudioEngine::Instance().Init();
	AudioBuffer* audiobuffer = new AudioBuffer( "data/sounds/music.wav" );
	AudioSource* audiosource = 0;
	if ( audiobuffer->IsValid() )
		// audiosource = new AudioSource( audiobuffer );
	if ( audiosource )
		audiosource->Play();

	float shift = 1.f;
	float soundShiftStep = 0.0075;
	float pitch = 1.f;
	float stepPitch = 0.0075;

	// Práctica de Interfaces

	font = resourceManager.LoadFont( "data/fonts/monospaced.png" );

	CreateMenu();
	glfwSetMouseButtonCallback( MouseButtonCallback );
	glfwSetMousePosCallback( MousePosCallback );

	while ( screen.IsOpened() && !screen.KeyPressed( GLFW_KEY_BACKSPACE ) )
	{
		renderer.Clear();

		// -----------------------------------

		if ( screen.KeyPressed( GLFW_KEY_RIGHT ) )
		{
			// Right
			shift += soundShiftStep;
		}
		if ( screen.KeyPressed( GLFW_KEY_LEFT ) )
		{
			// Left
			shift -= soundShiftStep;
		}
		if ( screen.KeyPressed( GLFW_KEY_UP ) )
		{
			// Up
			pitch += stepPitch;
		}
		if ( screen.KeyPressed( GLFW_KEY_DOWN ) )
		{
			// Down
			pitch -= stepPitch;
		}

		if ( audiosource )
		{
			audiosource->SetPitch( pitch );
			audiosource->SetPosition( shift, 0, 0 );
		}
		
		// -----------------------------------


		if ( renderScene == eScene::START )
		{
			if ( screen.KeyPressed( GLFW_KEY_ESC ) )
			{
				// Return to menu
				CreateMenu();
			}
		}
		else if ( renderScene == eScene::SETTING )
		{
			if ( screen.KeyPressed( GLFW_KEY_ESC ) )
			{
				// Return to menu
				CreateMenu();
			}
		}

		GUIManager::instance().update();
		GUIManager::instance().render();

		// Refrescamos la pantalla
		screen.Refresh();
	}

	// Liberamos recursos
	resourceManager.FreeResources();
	GUIManager::instance().end();
	AudioEngine::Instance().End();

	return 0;
}
コード例 #5
0
ファイル: main.cpp プロジェクト: kanc/UTAD
int main(int argc, char* argv[]) 
{
	Screen &screen = Screen::Instance();
	const Renderer &render = Renderer::Instance();

	screen.Open(800, 600, false);

	//inicamos el motor de sonido
	AudioEngine::Instance().Init();

	//cargamos recursos
	AudioBuffer* wav = ResourceManager::Instance().LoadAudioBuffer("data/music.wav");
	AudioSource source = AudioSource(wav);
	Font* fuente = ResourceManager::Instance().LoadFont("data/arial16_2.png");
				
	float x,y,pitch;
	x = screen.GetWidth() / 2;
	y = screen.GetHeight() / 2;
	pitch = 1;
	source.SetGain(2);

	//sitamos el listener en el centro de la pantalla
	Listener::Instance().SetPosition(x, y, 0);	
		
	while (screen.IsOpened()  &&  !screen.KeyPressed(GLFW_KEY_ESC)) 
	{		
		render.Clear();

		//actualizamos la posicion del source y su pitch
		source.SetPosition(x, y, 0);
		source.SetPitch(pitch);

		if (!source.IsPlaying())
			source.Play();
		
		if (screen.KeyPressed(GLFW_KEY_LEFT))
			x-=50 * screen.ElapsedTime();
		else if (screen.KeyPressed(GLFW_KEY_RIGHT))
			x+=50 * screen.ElapsedTime();
		else if (screen.KeyPressed(GLFW_KEY_UP))
			pitch+= screen.ElapsedTime();
		else if (screen.KeyPressed(GLFW_KEY_DOWN))
			pitch-= screen.ElapsedTime();
		else if (screen.KeyPressed(GLFW_KEY_SPACE))
		{
			x = screen.GetWidth() / 2;
			pitch = 1;
		}

		x = WrapValue(x, screen.GetWidth());		

		//pintamos texto informativo y posicion de la fuente
		render.SetColor(255,125,0,255);
		render.DrawEllipse(x,y,10,10);

		render.SetColor(255,255,255,255);
		render.DrawText(fuente, String("cursor izquierda : desplazar fuente a la izquierda"),10,10);
		render.DrawText(fuente, String("cursor derecha : desplazar fuente a la derecha"),10,30);
		render.DrawText(fuente, String("cursor arriba : aumentar pitch"),10,50);
		render.DrawText(fuente, String("cursor abajo : disminuir pitch"),10,70);
		render.DrawText(fuente, String("espacio : resetear pitch y posicion"),10,90);
		render.DrawText(fuente, String("pitch: ") + String::FromFloat(pitch),10,110);
		render.DrawText(fuente, String("(Listener)"),(screen.GetWidth() / 2) - fuente->GetTextWidth(String("(Listener)")) / 2,  screen.GetHeight() / 2 + 20);

        screen.Refresh();
	}

	//paramos el source
	source.Stop();

	//paramos motor audio y liberamos recursos
	AudioEngine::Instance().Finish();
	ResourceManager::Instance().FreeResources();
		
	return 0;
}