diff --git a/Cargo.lock b/Cargo.lock index 402e04a..536f2ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -111,6 +111,7 @@ dependencies = [ "ffmpeg-next", "kira", "num-rational", + "rand", "sdl2", "serde", "serde_json", 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/assets/sound/combo/chu-imsae-by-AnSukseon-5.wav b/game/assets/sound/combo/chu-imsae-by-AnSukseon-5.wav new file mode 100644 index 0000000..a9abc38 --- /dev/null +++ b/game/assets/sound/combo/chu-imsae-by-AnSukseon-5.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8823663c119d5b698de8e8d941e6e455a868752c44ded6f3f2241ee189084dd8 +size 591828 diff --git a/game/assets/sound/combo/chu-imsae-by-JeongSunim-2.wav b/game/assets/sound/combo/chu-imsae-by-JeongSunim-2.wav new file mode 100644 index 0000000..5e821ee --- /dev/null +++ b/game/assets/sound/combo/chu-imsae-by-JeongSunim-2.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b215d96407e66b95a649b97950611f16d7dfc2026005af0dffe506ef1eb37ce9 +size 662856 diff --git a/game/assets/sound/combo/chu-imsae-by-JungHoeseok-1.wav b/game/assets/sound/combo/chu-imsae-by-JungHoeseok-1.wav new file mode 100644 index 0000000..61ead79 --- /dev/null +++ b/game/assets/sound/combo/chu-imsae-by-JungHoeseok-1.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b07fca9c53e20f746215c51abd397f979b031eb01d63858ef1eee7a9608cdb73 +size 399732 diff --git a/game/assets/sound/combo/chu-imsae-by-JungHoeseok-2.wav b/game/assets/sound/combo/chu-imsae-by-JungHoeseok-2.wav new file mode 100644 index 0000000..e2017fb --- /dev/null +++ b/game/assets/sound/combo/chu-imsae-by-JungHoeseok-2.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9e010229612ae46d6bc28bc8c5d1b8b3a2675c9bfb46c690dc9f080e5d43a0ab +size 456816 diff --git a/game/assets/sound/combo/chu-imsae-by-JungHoeseok-5.wav b/game/assets/sound/combo/chu-imsae-by-JungHoeseok-5.wav new file mode 100644 index 0000000..7aac641 --- /dev/null +++ b/game/assets/sound/combo/chu-imsae-by-JungHoeseok-5.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:930de48402e89aed423d2eeb3428999ebdf2f5481882874a63da36bfbb33ac86 +size 381144 diff --git a/game/assets/sound/combo/chu-imsae-by-JungHoeseok-6.wav b/game/assets/sound/combo/chu-imsae-by-JungHoeseok-6.wav new file mode 100644 index 0000000..94baf77 --- /dev/null +++ b/game/assets/sound/combo/chu-imsae-by-JungHoeseok-6.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:116ccf9b0b003c5375b37bf3ec13ea75fce6e63b71201c5ccd3ce9153a693044 +size 381144 diff --git a/game/assets/sound/combo/chu-imsae-by-LeeChunhui-1.wav b/game/assets/sound/combo/chu-imsae-by-LeeChunhui-1.wav new file mode 100644 index 0000000..55669bb --- /dev/null +++ b/game/assets/sound/combo/chu-imsae-by-LeeChunhui-1.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1aca4aadb5444572fb19de86c296ee97dcab61e65d5665c4295abf29c523d4e7 +size 341208 diff --git a/game/assets/sound/combo/chu-imsae-by-LeeChunhui-3.wav b/game/assets/sound/combo/chu-imsae-by-LeeChunhui-3.wav new file mode 100644 index 0000000..1488b47 --- /dev/null +++ b/game/assets/sound/combo/chu-imsae-by-LeeChunhui-3.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:08e7f80ae7ab023c6ac48af25e8078ee0d24225cd1b4a32739c880773968dd20 +size 239252 diff --git a/game/assets/sound/combo/chu-imsae-by-LeeChunhui-6.wav b/game/assets/sound/combo/chu-imsae-by-LeeChunhui-6.wav new file mode 100644 index 0000000..8d78c7d --- /dev/null +++ b/game/assets/sound/combo/chu-imsae-by-LeeChunhui-6.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:42d32c89c449db79e3ad30609fd1b9a4bf9995758f4c33c9fdff537cc2810e7d +size 287804 diff --git a/game/assets/sound/combo/chu-imsae-by-LeeChunhui-7.wav b/game/assets/sound/combo/chu-imsae-by-LeeChunhui-7.wav new file mode 100644 index 0000000..59dfd0f --- /dev/null +++ b/game/assets/sound/combo/chu-imsae-by-LeeChunhui-7.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d7ff5528644724cc94ca3b735ad11959473fa5881b223eb283f3b7eaef39f1c1 +size 144576 diff --git a/game/src/game/game_player.rs b/game/src/game/game_player.rs index 598452a..c1d6f9c 100644 --- a/game/src/game/game_player.rs +++ b/game/src/game/game_player.rs @@ -53,7 +53,7 @@ pub(crate) fn play_song( let song_path_string = song.audio_filename.clone(); // Load hit sound data - let mut effect_sounds = EffectSoundPlayer::new(); + let mut effect_sounds: EffectSoundPlayer = EffectSoundPlayer::new(); // to receive coin input while loading the audio file, // loading should be done in separated thread. @@ -194,7 +194,10 @@ pub(crate) fn play_song( janggu_state_with_tick.update(input_now, tick_now); effect_sounds.play_janggu_sound(&janggu_state_with_tick, &mut common_context.audio_manager); - + effect_sounds.play_combo_sound( + &chart_player.game_result(), + &mut common_context.audio_manager, + ); // display notes and accuracy if tick_now >= 0 { chart_player.judge(&janggu_state_with_tick, tick_now); diff --git a/game/src/game/game_player/effect_sound_player.rs b/game/src/game/game_player/effect_sound_player.rs index 9dde82e..ef5eeff 100644 --- a/game/src/game/game_player/effect_sound_player.rs +++ b/game/src/game/game_player/effect_sound_player.rs @@ -5,10 +5,11 @@ use kira::{ PlaybackState, }, }; +use rand::seq::SliceRandom; -use crate::constants::DEFAULT_SOUND_PATH as SOUND_PATH; +use crate::{constants::DEFAULT_SOUND_PATH as SOUND_PATH, game}; -use super::janggu_state_with_tick::JangguStateWithTick; +use super::{game_result::GameResult, janggu_state_with_tick::JangguStateWithTick}; fn load_hit_sounds() -> [StaticSoundData; 2] { [ @@ -25,6 +26,61 @@ fn load_hit_sounds() -> [StaticSoundData; 2] { ] } +fn load_combo_sounds() -> [StaticSoundData; 10] { + [ + StaticSoundData::from_file( + SOUND_PATH.to_owned() + "/combo/chu-imsae-by-AnSukseon-5.wav", + StaticSoundSettings::default(), + ) + .expect("Failed to load combo sound"), + StaticSoundData::from_file( + SOUND_PATH.to_owned() + "/combo/chu-imsae-by-JeongSunim-2.wav", + StaticSoundSettings::default(), + ) + .expect("Failed to load combo sound"), + StaticSoundData::from_file( + SOUND_PATH.to_owned() + "/combo/chu-imsae-by-JungHoeseok-1.wav", + StaticSoundSettings::default(), + ) + .expect("Failed to load combo sound"), + StaticSoundData::from_file( + SOUND_PATH.to_owned() + "/combo/chu-imsae-by-JungHoeseok-2.wav", + StaticSoundSettings::default(), + ) + .expect("Failed to load combo sound"), + StaticSoundData::from_file( + SOUND_PATH.to_owned() + "/combo/chu-imsae-by-JungHoeseok-5.wav", + StaticSoundSettings::default(), + ) + .expect("Failed to load combo sound"), + StaticSoundData::from_file( + SOUND_PATH.to_owned() + "/combo/chu-imsae-by-JungHoeseok-6.wav", + StaticSoundSettings::default(), + ) + .expect("Failed to load combo sound"), + StaticSoundData::from_file( + SOUND_PATH.to_owned() + "/combo/chu-imsae-by-LeeChunhui-1.wav", + StaticSoundSettings::default(), + ) + .expect("Failed to load combo sound"), + StaticSoundData::from_file( + SOUND_PATH.to_owned() + "/combo/chu-imsae-by-LeeChunhui-3.wav", + StaticSoundSettings::default(), + ) + .expect("Failed to load combo sound"), + StaticSoundData::from_file( + SOUND_PATH.to_owned() + "/combo/chu-imsae-by-LeeChunhui-6.wav", + StaticSoundSettings::default(), + ) + .expect("Failed to load combo sound"), + StaticSoundData::from_file( + SOUND_PATH.to_owned() + "/combo/chu-imsae-by-LeeChunhui-7.wav", + StaticSoundSettings::default(), + ) + .expect("Failed to load combo sound"), + ] +} + struct EffectSoundHandles { left_stick: Option, right_stick: Option, @@ -39,8 +95,10 @@ impl EffectSoundHandles { } } pub struct EffectSoundPlayer { - hit_sounds: [StaticSoundData; 2], effect_sound_play_handles: EffectSoundHandles, + hit_sounds: [StaticSoundData; 2], + combo_sounds: [StaticSoundData; 10], + combo_sound_played: bool, } impl EffectSoundPlayer { @@ -48,6 +106,8 @@ impl EffectSoundPlayer { EffectSoundPlayer { effect_sound_play_handles: EffectSoundHandles::new(), hit_sounds: load_hit_sounds(), + combo_sounds: load_combo_sounds(), + combo_sound_played: false, } } @@ -87,4 +147,23 @@ impl EffectSoundPlayer { } } } + + pub fn play_combo_sound(&mut self, game_result: &GameResult, audio_manager: &mut AudioManager) { + if game_result.combo > 0 && (game_result.combo % 10 == 0) { + if !self.combo_sound_played { + if let Some(combo_sound) = self.combo_sounds.choose(&mut rand::thread_rng()) { + audio_manager + .play( + combo_sound + .clone() + .with_settings(StaticSoundSettings::default().volume(20.0)), + ) + .expect("Failed to play combo sound"); + self.combo_sound_played = true; + } + } + } else { + self.combo_sound_played = false; + } + } }