Add in death sounds.

master
sigonasr2 1 year ago
parent 90a2b5c562
commit 1801f82248
  1. 3
      olcCodeJam2023Entry/Sound.h
  2. 14
      olcCodeJam2023Entry/Unit.cpp
  3. 1
      olcCodeJam2023Entry/Unit.h
  4. 5
      olcCodeJam2023Entry/VirusAttack.cpp

@ -22,5 +22,8 @@ namespace Sound{
TURRET,
MEMORY_GUARD,
SPAWN,
DEAD1,
DEAD2,
DEAD3,
};
}

@ -655,6 +655,20 @@ int Unit::GetBits(Marker&m){
return activeBits;
}
void Unit::_OnDeath(std::vector<std::unique_ptr<Audio>>&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<std::unique_ptr<Audio>>&SOUNDS){}
int Unit::GetHealth(){

@ -50,6 +50,7 @@ public:
virtual void Draw(TileTransformedView&game,std::vector<std::unique_ptr<Renderable>>&IMAGES);
virtual void DrawHud(TileTransformedView&game,std::vector<std::unique_ptr<Renderable>>&IMAGES);
void _DrawHud(TileTransformedView&game,std::vector<std::unique_ptr<Renderable>>&IMAGES,bool unitMetersGreyedOut);
void _OnDeath(std::vector<std::unique_ptr<Audio>>&SOUNDS);
virtual void OnDeath(std::vector<std::unique_ptr<Audio>>&SOUNDS);
bool IsFriendly();
bool IsSelected();

@ -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_ptr<Unit>u){
if(u->GetHealth()==0){
u->OnDeath(SOUNDS);
u->_OnDeath(SOUNDS);
deathAnimations.emplace_back(std::make_unique<DeathAnimation>(this,u->GetPos(),u->GetImage(),*IMAGES[MATRIX],u->IsFriendly()));
return true;
} else {

Loading…
Cancel
Save