From b4e88f37502310583e42e7899544e9e19470aee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=A1=ED=95=98=EB=B9=88?= Date: Wed, 22 May 2024 23:52:32 +0900 Subject: [PATCH] feat: impl playing random sound impl --- game/Cargo.toml | 1 + .../game/game_player/effect_sound_player.rs | 33 ++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/game/Cargo.toml b/game/Cargo.toml index 7488bb5..025c173 100644 --- a/game/Cargo.toml +++ b/game/Cargo.toml @@ -20,6 +20,7 @@ bidrum-data-struct-lib = { path = "../data-struct-lib" } device_query = "2.0.0" ezing = "0.2.1" const_format = "0.2.32" +rand = "0.8" [profile.dev.package.kira] opt-level = 3 diff --git a/game/src/game/game_player/effect_sound_player.rs b/game/src/game/game_player/effect_sound_player.rs index febce46..aea1fe1 100644 --- a/game/src/game/game_player/effect_sound_player.rs +++ b/game/src/game/game_player/effect_sound_player.rs @@ -5,6 +5,7 @@ use kira::{ PlaybackState, }, }; +use rand::seq::SliceRandom; use crate::{constants::DEFAULT_SOUND_PATH as SOUND_PATH, game}; @@ -29,52 +30,52 @@ fn load_combo_sounds() -> [StaticSoundData; 10] { [ StaticSoundData::from_file( SOUND_PATH.to_owned() + "/combo/Chu-imsaebyAnSukseon_5.wav", - StaticSoundSettings::default(), + StaticSoundSettings::default().volume(50.0), ) .expect("Failed to load combo sound"), StaticSoundData::from_file( SOUND_PATH.to_owned() + "/combo/Chu-imsaebyJeongSunim_2.wav", - StaticSoundSettings::default(), + StaticSoundSettings::default().volume(50.0), ) .expect("Failed to load combo sound"), StaticSoundData::from_file( SOUND_PATH.to_owned() + "/combo/Chu-imsaebyJungHoeseok_1.wav", - StaticSoundSettings::default(), + StaticSoundSettings::default().volume(50.0), ) .expect("Failed to load combo sound"), StaticSoundData::from_file( SOUND_PATH.to_owned() + "/combo/Chu-imsaebyJungHoeseok_2.wav", - StaticSoundSettings::default(), + StaticSoundSettings::default().volume(50.0), ) .expect("Failed to load combo sound"), StaticSoundData::from_file( SOUND_PATH.to_owned() + "/combo/Chu-imsaebyJungHoeseok_5.wav", - StaticSoundSettings::default(), + StaticSoundSettings::default().volume(50.0), ) .expect("Failed to load combo sound"), StaticSoundData::from_file( SOUND_PATH.to_owned() + "/combo/Chu-imsaebyJungHoeseok_6.wav", - StaticSoundSettings::default(), + StaticSoundSettings::default().volume(50.0), ) .expect("Failed to load combo sound"), StaticSoundData::from_file( SOUND_PATH.to_owned() + "/combo/Chu-imsaebyLeeChunhui_1.wav", - StaticSoundSettings::default(), + StaticSoundSettings::default().volume(50.0), ) .expect("Failed to load combo sound"), StaticSoundData::from_file( SOUND_PATH.to_owned() + "/combo/Chu-imsaebyLeeChunhui_3.wav", - StaticSoundSettings::default(), + StaticSoundSettings::default().volume(50.0), ) .expect("Failed to load combo sound"), StaticSoundData::from_file( SOUND_PATH.to_owned() + "/combo/Chu-imsaebyLeeChunhui_6.wav", - StaticSoundSettings::default(), + StaticSoundSettings::default().volume(50.0), ) .expect("Failed to load combo sound"), StaticSoundData::from_file( SOUND_PATH.to_owned() + "/combo/Chu-imsaebyLeeChunhui_7.wav", - StaticSoundSettings::default(), + StaticSoundSettings::default().volume(50.0), ) .expect("Failed to load combo sound"), ] @@ -148,14 +149,14 @@ impl EffectSoundPlayer { } pub fn play_combo_sound(&mut self, game_result: &GameResult, audio_manager: &mut AudioManager) { - let combo_sound = self.combo_sounds[0].clone(); - if game_result.combo > 0 && (game_result.combo % 10 == 0) { if !self.combo_sound_played { - let new_handle = audio_manager - .play(combo_sound.clone()) - .expect("Failed to play combo sound"); - self.combo_sound_played = true; + if let Some(combo_sound) = self.combo_sounds.choose(&mut rand::thread_rng()) { + audio_manager + .play(combo_sound.clone()) + .expect("Failed to play combo sound"); + self.combo_sound_played = true; + } } } else { self.combo_sound_played = false;