Skip to content

Commit

Permalink
Add SFX pitch randomization
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Jul 29, 2024
1 parent 805faa2 commit bbc1f5d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/game/combat/death.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bevy::prelude::*;
use bevy_kira_audio::prelude::*;
use rand::Rng as _;

use crate::screen::playing::PlayingAssets;
use crate::util::prelude::*;
Expand Down Expand Up @@ -73,5 +74,8 @@ fn play_death_sfx(
return;
}

audio.play(assets.sfx_restart.clone()).with_volume(1.0);
audio
.play(assets.sfx_restart.clone())
.with_volume(1.0)
.with_playback_rate(rand::thread_rng().gen_range(0.8..1.4));
}
6 changes: 5 additions & 1 deletion src/game/combat/hit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use avian2d::prelude::*;
use bevy::prelude::*;
use bevy_kira_audio::prelude::*;
use rand::Rng as _;

use crate::core::UpdateSet;
use crate::game::cleanup::RemoveOnTimer;
Expand Down Expand Up @@ -88,5 +89,8 @@ fn play_hurt_sfx(
return;
}

audio.play(assets.sfx_hurt.clone()).with_volume(1.0);
audio
.play(assets.sfx_hurt.clone())
.with_volume(1.0)
.with_playback_rate(rand::thread_rng().gen_range(0.7..1.6));
}
4 changes: 2 additions & 2 deletions src/screen/intro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ fn body(mut entity: EntityWorldMut) {
.with_children(|children| {
for (i, text) in [
"Cards are played to the rhythm,",
"use your mouse to aim.",
"Show off your moves to impress 'em,",
"using your mouse to aim.",
"Show off your dance moves with 'em,",
"reach [b]Level 10[r] for fame!",
]
.into_iter()
Expand Down
12 changes: 9 additions & 3 deletions src/screen/playing/level_up_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,9 @@ fn card_swap_left(
deck_display_query: Query<&Selection, With<IsDeckDisplay>>,
mut deck_query: Query<&mut Deck>,
) {
audio.play(assets.sfx_ui_hover.clone());
audio
.play(assets.sfx_ui_hover.clone())
.with_playback_rate(rand::thread_rng().gen_range(0.7..1.6));
for selection in &deck_display_query {
let mut deck = c!(deck_query.get_mut(selection.0));
deck.swap(-1);
Expand All @@ -457,7 +459,9 @@ fn card_swap_right(
deck_display_query: Query<&Selection, With<IsDeckDisplay>>,
mut deck_query: Query<&mut Deck>,
) {
audio.play(assets.sfx_ui_hover.clone());
audio
.play(assets.sfx_ui_hover.clone())
.with_playback_rate(rand::thread_rng().gen_range(0.7..1.6));
for selection in &deck_display_query {
let mut deck = c!(deck_query.get_mut(selection.0));
deck.swap(1);
Expand All @@ -470,7 +474,9 @@ fn card_discard(
deck_display_query: Query<&Selection, With<IsDeckDisplay>>,
mut deck_query: Query<&mut Deck>,
) {
audio.play(assets.sfx_ui_click.clone());
audio
.play(assets.sfx_ui_click.clone())
.with_playback_rate(rand::thread_rng().gen_range(0.8..1.4));
for selection in &deck_display_query {
let mut deck = c!(deck_query.get_mut(selection.0));
deck.discard();
Expand Down
11 changes: 9 additions & 2 deletions src/ui/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use bevy::prelude::*;
use bevy::reflect::GetTypeRegistration;
use bevy_kira_audio::prelude::*;
use bevy_mod_picking::prelude::*;
use rand::Rng as _;

use crate::animation::offset::Offset;
use crate::core::UpdateSet;
Expand Down Expand Up @@ -109,10 +110,16 @@ fn play_interaction_sfx(

match interaction {
Interaction::Hovered => {
audio.play(assets.sfx_ui_hover.clone()).with_volume(0.6);
audio
.play(assets.sfx_ui_hover.clone())
.with_volume(0.6)
.with_playback_rate(rand::thread_rng().gen_range(0.7..1.6));
},
Interaction::Pressed => {
audio.play(assets.sfx_ui_click.clone()).with_volume(0.6);
audio
.play(assets.sfx_ui_click.clone())
.with_volume(0.6)
.with_playback_rate(rand::thread_rng().gen_range(0.7..1.6));
},
_ => (),
}
Expand Down

0 comments on commit bbc1f5d

Please sign in to comment.