From 18b54a3c7520a42e6e1468a6ef3f6c68ff9e83d6 Mon Sep 17 00:00:00 2001 From: Aakash Singh Date: Sun, 4 May 2025 04:29:25 +0530 Subject: [PATCH] added explosion sound --- Space-Invaders/Header/Global/Config.h | 2 ++ Space-Invaders/Header/Sound/SoundService.h | 2 ++ Space-Invaders/Source/Global/Config.cpp | 2 ++ Space-Invaders/Source/Sound/SoundService.cpp | 7 +++++++ 4 files changed, 13 insertions(+) diff --git a/Space-Invaders/Header/Global/Config.h b/Space-Invaders/Header/Global/Config.h index f5ba50ab9..955255fb8 100644 --- a/Space-Invaders/Header/Global/Config.h +++ b/Space-Invaders/Header/Global/Config.h @@ -35,7 +35,9 @@ namespace Global static const sf::String background_music_path; static const sf::String button_click_sound_path; static const sf::String bullet_fire_sound_path; + static const sf::String explosion_sound_path; static const sf::String powerup_enabled_sound_path; static const sf::String powerup_disabled_sound_path; + }; } diff --git a/Space-Invaders/Header/Sound/SoundService.h b/Space-Invaders/Header/Sound/SoundService.h index 5d354e880..5c7799da9 100644 --- a/Space-Invaders/Header/Sound/SoundService.h +++ b/Space-Invaders/Header/Sound/SoundService.h @@ -28,6 +28,8 @@ namespace Sound sf::SoundBuffer buffer_powerup_enabled; sf::SoundBuffer buffer_powerup_disabled; + sf::SoundBuffer buffer_explosion_sound; + void loadBackgroundMusicFromFile(); void loadSoundFromFile(); diff --git a/Space-Invaders/Source/Global/Config.cpp b/Space-Invaders/Source/Global/Config.cpp index 716cd56ae..eb019fc28 100644 --- a/Space-Invaders/Source/Global/Config.cpp +++ b/Space-Invaders/Source/Global/Config.cpp @@ -59,4 +59,6 @@ namespace Global const sf::String Config::powerup_enabled_sound_path = "assets/sounds/powerup_enabled.ogg"; const sf::String Config::powerup_disabled_sound_path = "assets/sounds/powerup_disabled.ogg"; + + const sf::String Config::explosion_sound_path = "assets/sounds/explosion.wav"; } \ No newline at end of file diff --git a/Space-Invaders/Source/Sound/SoundService.cpp b/Space-Invaders/Source/Sound/SoundService.cpp index 5eef27bc7..797a077f2 100644 --- a/Space-Invaders/Source/Sound/SoundService.cpp +++ b/Space-Invaders/Source/Sound/SoundService.cpp @@ -27,6 +27,8 @@ namespace Sound printf("Error loading background music file"); if (!buffer_powerup_disabled.loadFromFile(Config::powerup_disabled_sound_path)) printf("Error loading background music file"); + if (!buffer_explosion_sound.loadFromFile(Config::explosion_sound_path)) + printf("error loading bakground music file"); } void SoundService::playSound(SoundType soundType) @@ -54,6 +56,11 @@ namespace Sound powerup_sound_effect.play(); break; + case SoundType::EXPLOSION: + sound_effect.setBuffer(buffer_explosion_sound); + sound_effect.play(); + break; + default: printf("Invalid sound type"); return;