mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-10 14:07:59 -06:00
refactor(audio): rename eat() to waka(), use play(Sound) for death() instead
This commit is contained in:
12
src/audio.rs
12
src/audio.rs
@@ -185,13 +185,13 @@ impl Audio {
|
|||||||
/// Automatically rotates through the four eating sound assets. The sound plays on channel 0 and the internal sound index
|
/// Automatically rotates through the four eating sound assets. The sound plays on channel 0 and the internal sound index
|
||||||
/// advances to the next variant. Silently returns if audio is disabled, muted,
|
/// advances to the next variant. Silently returns if audio is disabled, muted,
|
||||||
/// or no sounds were loaded successfully.
|
/// or no sounds were loaded successfully.
|
||||||
pub fn eat(&mut self) {
|
pub fn waka(&mut self) {
|
||||||
if self.disabled || self.muted || self.sounds.is_empty() {
|
if self.disabled || self.muted || self.sounds.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(chunk) = self.sounds.get(&Sound::Waka(self.next_waka_index)) {
|
if let Some(chunk) = self.sounds.get(&Sound::Waka(self.next_waka_index)) {
|
||||||
match mixer::Channel(0).play(chunk, 0) {
|
match mixer::Channel::all().play(chunk, 0) {
|
||||||
Ok(channel) => {
|
Ok(channel) => {
|
||||||
tracing::trace!("Playing sound #{} on channel {:?}", self.next_waka_index + 1, channel);
|
tracing::trace!("Playing sound #{} on channel {:?}", self.next_waka_index + 1, channel);
|
||||||
}
|
}
|
||||||
@@ -203,14 +203,14 @@ impl Audio {
|
|||||||
self.next_waka_index = (self.next_waka_index + 1) & 3;
|
self.next_waka_index = (self.next_waka_index + 1) & 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Plays the death sound effect.
|
/// Plays the provided sound effect once.
|
||||||
pub fn death(&mut self) {
|
pub fn play(&mut self, sound: Sound) {
|
||||||
if self.disabled || self.muted {
|
if self.disabled || self.muted {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(chunk) = self.sounds.get(&Sound::PacmanDeath) {
|
if let Some(chunk) = self.sounds.get(&sound) {
|
||||||
mixer::Channel::all().play(chunk, 0).ok();
|
let _ = mixer::Channel::all().play(chunk, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ pub fn audio_system(
|
|||||||
AudioEvent::PlayEat => {
|
AudioEvent::PlayEat => {
|
||||||
if !audio.0.is_disabled() && !audio_state.muted {
|
if !audio.0.is_disabled() && !audio_state.muted {
|
||||||
trace!(sound_index = audio_state.sound_index, "Playing eat sound");
|
trace!(sound_index = audio_state.sound_index, "Playing eat sound");
|
||||||
audio.0.eat();
|
audio.0.waka();
|
||||||
// Update the sound index for cycling through sounds
|
// Update the sound index for cycling through sounds
|
||||||
audio_state.sound_index = (audio_state.sound_index + 1) % 4;
|
audio_state.sound_index = (audio_state.sound_index + 1) % 4;
|
||||||
// 4 eat sounds available
|
// 4 eat sounds available
|
||||||
@@ -79,7 +79,7 @@ pub fn audio_system(
|
|||||||
AudioEvent::PlayDeath => {
|
AudioEvent::PlayDeath => {
|
||||||
if !audio.0.is_disabled() && !audio_state.muted {
|
if !audio.0.is_disabled() && !audio_state.muted {
|
||||||
trace!("Playing death sound");
|
trace!("Playing death sound");
|
||||||
audio.0.death();
|
audio.0.play(crate::audio::Sound::PacmanDeath);
|
||||||
} else {
|
} else {
|
||||||
debug!(
|
debug!(
|
||||||
disabled = audio.0.is_disabled(),
|
disabled = audio.0.is_disabled(),
|
||||||
|
|||||||
Reference in New Issue
Block a user