From 1801f822483a9867786a6731fba56e3642752fd2 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sun, 3 Sep 2023 07:22:01 -0500 Subject: [PATCH] Add in death sounds. --- olcCodeJam2023Entry/Sound.h | 3 +++ olcCodeJam2023Entry/Unit.cpp | 14 ++++++++++++++ olcCodeJam2023Entry/Unit.h | 1 + olcCodeJam2023Entry/VirusAttack.cpp | 5 ++++- 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/olcCodeJam2023Entry/Sound.h b/olcCodeJam2023Entry/Sound.h index 1318616..6f68ecd 100644 --- a/olcCodeJam2023Entry/Sound.h +++ b/olcCodeJam2023Entry/Sound.h @@ -22,5 +22,8 @@ namespace Sound{ TURRET, MEMORY_GUARD, SPAWN, + DEAD1, + DEAD2, + DEAD3, }; } \ No newline at end of file diff --git a/olcCodeJam2023Entry/Unit.cpp b/olcCodeJam2023Entry/Unit.cpp index f3788f7..3e0bbdb 100644 --- a/olcCodeJam2023Entry/Unit.cpp +++ b/olcCodeJam2023Entry/Unit.cpp @@ -655,6 +655,20 @@ int Unit::GetBits(Marker&m){ return activeBits; } +void Unit::_OnDeath(std::vector>&SOUNDS){ + switch(rand()%3){ + case 0:{ + SOUNDS[Sound::DEAD1]->Play(GetPos()); + }break; + case 1:{ + SOUNDS[Sound::DEAD2]->Play(GetPos()); + }break; + case 2:{ + SOUNDS[Sound::DEAD3]->Play(GetPos()); + }break; + } + OnDeath(SOUNDS); +} void Unit::OnDeath(std::vector>&SOUNDS){} int Unit::GetHealth(){ diff --git a/olcCodeJam2023Entry/Unit.h b/olcCodeJam2023Entry/Unit.h index 5966f5c..3cc7ba2 100644 --- a/olcCodeJam2023Entry/Unit.h +++ b/olcCodeJam2023Entry/Unit.h @@ -50,6 +50,7 @@ public: virtual void Draw(TileTransformedView&game,std::vector>&IMAGES); virtual void DrawHud(TileTransformedView&game,std::vector>&IMAGES); void _DrawHud(TileTransformedView&game,std::vector>&IMAGES,bool unitMetersGreyedOut); + void _OnDeath(std::vector>&SOUNDS); virtual void OnDeath(std::vector>&SOUNDS); bool IsFriendly(); bool IsSelected(); diff --git a/olcCodeJam2023Entry/VirusAttack.cpp b/olcCodeJam2023Entry/VirusAttack.cpp index 896e14e..8bfced5 100644 --- a/olcCodeJam2023Entry/VirusAttack.cpp +++ b/olcCodeJam2023Entry/VirusAttack.cpp @@ -350,6 +350,9 @@ void VirusAttack::InitializeSounds(){ LoadSound(Sound::TURRET,"turret.mp3"); LoadSound(Sound::MEMORY_GUARD,"memoryguard.mp3"); LoadSound(Sound::SPAWN,"spawn.mp3"); + LoadSound(Sound::DEAD1,"dead1.mp3"); + LoadSound(Sound::DEAD2,"dead2.mp3"); + LoadSound(Sound::DEAD3,"dead3.mp3"); } bool VirusAttack::UnitCreationClickHandled(){ @@ -899,7 +902,7 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ std::erase_if(units,[&](std::shared_ptru){ if(u->GetHealth()==0){ - u->OnDeath(SOUNDS); + u->_OnDeath(SOUNDS); deathAnimations.emplace_back(std::make_unique(this,u->GetPos(),u->GetImage(),*IMAGES[MATRIX],u->IsFriendly())); return true; } else {