Skip to content

Commit

Permalink
Merge pull request #48 from cau-overchaos/BID-73--chu-imsae-effect-sound
Browse files Browse the repository at this point in the history
playing random combo sound
  • Loading branch information
boulce authored May 26, 2024
2 parents 14a5221 + b3e73d1 commit dd232fa
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions game/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions game/assets/sound/combo/chu-imsae-by-AnSukseon-5.wav
Git LFS file not shown
3 changes: 3 additions & 0 deletions game/assets/sound/combo/chu-imsae-by-JeongSunim-2.wav
Git LFS file not shown
3 changes: 3 additions & 0 deletions game/assets/sound/combo/chu-imsae-by-JungHoeseok-1.wav
Git LFS file not shown
3 changes: 3 additions & 0 deletions game/assets/sound/combo/chu-imsae-by-JungHoeseok-2.wav
Git LFS file not shown
3 changes: 3 additions & 0 deletions game/assets/sound/combo/chu-imsae-by-JungHoeseok-5.wav
Git LFS file not shown
3 changes: 3 additions & 0 deletions game/assets/sound/combo/chu-imsae-by-JungHoeseok-6.wav
Git LFS file not shown
3 changes: 3 additions & 0 deletions game/assets/sound/combo/chu-imsae-by-LeeChunhui-1.wav
Git LFS file not shown
3 changes: 3 additions & 0 deletions game/assets/sound/combo/chu-imsae-by-LeeChunhui-3.wav
Git LFS file not shown
3 changes: 3 additions & 0 deletions game/assets/sound/combo/chu-imsae-by-LeeChunhui-6.wav
Git LFS file not shown
3 changes: 3 additions & 0 deletions game/assets/sound/combo/chu-imsae-by-LeeChunhui-7.wav
Git LFS file not shown
7 changes: 5 additions & 2 deletions game/src/game/game_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
85 changes: 82 additions & 3 deletions game/src/game/game_player/effect_sound_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
[
Expand All @@ -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<StaticSoundHandle>,
right_stick: Option<StaticSoundHandle>,
Expand All @@ -39,15 +95,19 @@ 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 {
pub fn new() -> EffectSoundPlayer {
EffectSoundPlayer {
effect_sound_play_handles: EffectSoundHandles::new(),
hit_sounds: load_hit_sounds(),
combo_sounds: load_combo_sounds(),
combo_sound_played: false,
}
}

Expand Down Expand Up @@ -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;
}
}
}

0 comments on commit dd232fa

Please sign in to comment.