diff --git a/olcCodeJam2023Entry/VirusAttack.cpp b/olcCodeJam2023Entry/VirusAttack.cpp index 639c18a..1941b84 100644 --- a/olcCodeJam2023Entry/VirusAttack.cpp +++ b/olcCodeJam2023Entry/VirusAttack.cpp @@ -329,7 +329,7 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ AL.vecPos=game.GetWorldOffset()+GetScreenSize()/2; AL.OnUserUpdate(fElapsedTime); if (GetKey(olc::Key::P).bPressed){ - AS_Test.Play(1,1); + AS_Test.Play({0,0},1,1); } for(auto&tile:TileManager::visibleTiles){ diff --git a/olcCodeJam2023Entry/olcPGEX_AudioSource.h b/olcCodeJam2023Entry/olcPGEX_AudioSource.h index 7bf6d17..df59667 100644 --- a/olcCodeJam2023Entry/olcPGEX_AudioSource.h +++ b/olcCodeJam2023Entry/olcPGEX_AudioSource.h @@ -104,8 +104,10 @@ public: // Instruct Audio Listener to load this sound (if not loaded already) void LoadAudioSample(int ID, const char* fileName); + void PlayCentered(float speed = 1.0f, float vol = 1.0f, bool looping = false, bool paused = false); + // Play the Audio Sample, with given parameters - void Play(float speed = 1.0f, float vol = 1.0f, bool looping = false, bool paused = false); + void Play(vf2d pos, float speed = 1.0f, float vol = 1.0f, bool looping = false, bool paused = false); // Pause or Un-Pause - maintains the playback position and handle void Pause(bool pauseState = true); @@ -136,13 +138,34 @@ void olcPGEX_AudioSource::LoadAudioSample(int ID, const char* fileName) AL->LoadAudioSample(ID, fileName); } -void olcPGEX_AudioSource::Play(float speed, float vol, bool looping, bool paused) +void olcPGEX_AudioSource::PlayCentered(float speed, float vol, bool looping, bool paused) +{ + // Set parameters + fPlaySpeed = speed; + fVolume = vol; + bLooping = looping; + bPaused = paused; + this->pos = pos; + + // Assign a handle to this instance of the sound we are about to play + handle = AL->soloud.play(*AL->GetAudioSampleByID(nID)->wav, fVolume, 0.0f, bPaused); + + // Set speed and looping + AL->soloud.setRelativePlaySpeed(handle, fPlaySpeed); + AL->soloud.setLooping(handle, looping); + + // Update Play status + bIsPlaying = true; +} + +void olcPGEX_AudioSource::Play(vf2d pos, float speed, float vol, bool looping, bool paused) { // Set parameters fPlaySpeed = speed; fVolume = vol*std::max(0.f,abs(1-std::min(1.0f,(AL->GetDistance(pos)/1024.f)))); bLooping = looping; bPaused = paused; + this->pos = pos; // Assign a handle to this instance of the sound we are about to play handle = AL->soloud.play(*AL->GetAudioSampleByID(nID)->wav, fVolume, 0.0f, bPaused);