Skip to content

Commit

Permalink
feat: impl playing random sound
Browse files Browse the repository at this point in the history
impl
  • Loading branch information
송하빈 authored and 송하빈 committed May 22, 2024
1 parent cb58a7e commit b4e88f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
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
33 changes: 17 additions & 16 deletions game/src/game/game_player/effect_sound_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use kira::{
PlaybackState,
},
};
use rand::seq::SliceRandom;

use crate::{constants::DEFAULT_SOUND_PATH as SOUND_PATH, game};

Expand All @@ -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"),
]
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b4e88f3

Please sign in to comment.