Skip to content

Commit

Permalink
feat: Add striking sound with random pitch shift
Browse files Browse the repository at this point in the history
Closes #1
  • Loading branch information
PraxTube committed Feb 5, 2024
1 parent 78b6bf3 commit f195702
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ https://grappe.itch.io/medal

### Sounds

#### Swing

- https://freesound.org/people/Eponn/sounds/547040/
- https://freesound.org/people/spycrah/sounds/471097/
- https://freesound.org/people/Artninja/sounds/700220/

### Music

https://shononoki.itch.io/bullet-hell-music-pack
Expand Down
Binary file added assets/sounds/strike_sound.ogg
Binary file not shown.
4 changes: 4 additions & 0 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ pub struct GameAssets {
#[asset(path = "music/bgm.ogg")]
pub bgm: Handle<AudioSource>,

// --- SOUND ---
#[asset(path = "sounds/strike_sound.ogg")]
pub strike_sound: Handle<AudioSource>,

// --- FONT ---
#[asset(path = "fonts/PressStart2P.ttf")]
pub font: Handle<Font>,
Expand Down
1 change: 0 additions & 1 deletion src/audio/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod bgm;
mod sound;

#[allow(unused_imports)]
pub use sound::PlaySound;

use bevy::prelude::*;
Expand Down
20 changes: 20 additions & 0 deletions src/player/strike.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use std::time::Duration;

use rand::{thread_rng, Rng};

use bevy::prelude::*;
use bevy_rapier2d::prelude::*;
use bevy_trickfilm::prelude::*;

use crate::{
audio::PlaySound,
utils::{quat_from_vec2, FixedRotation},
world::camera::YSort,
GameAssets, GameState,
Expand All @@ -19,6 +22,7 @@ const OFFSET: Vec3 = Vec3::new(0.0, -10.0, 0.0);
const CHAIN_COOLDOWN: f32 = 0.35;
const STRIKE_COOLDOWN: f32 = 0.4;
const STRIKE_CHAIN_COUNT: usize = 3;
const SOUND_PITCH_CHANGE: f64 = 0.1;

#[derive(Resource, Default)]
struct StrikeCooldown {
Expand Down Expand Up @@ -120,6 +124,21 @@ fn despawn_strikes(
}
}

fn play_strike_sound(
assets: Res<GameAssets>,
mut ev_spawn_strike: EventReader<SpawnStrike>,
mut ev_play_sound: EventWriter<PlaySound>,
) {
let mut rng = thread_rng();
for _ in ev_spawn_strike.read() {
ev_play_sound.send(PlaySound {
clip: assets.strike_sound.clone(),
playback_rate: 1.0 + rng.gen_range(-1.0..1.0) * SOUND_PITCH_CHANGE,
..default()
});
}
}

fn trigger_strike(
player_input: Res<PlayerInput>,
mouse_coords: Res<MouseWorldCoords>,
Expand Down Expand Up @@ -197,6 +216,7 @@ impl Plugin for PlayerStrikePlugin {
(
spawn_strikes,
despawn_strikes,
play_strike_sound,
trigger_strike,
reset_chain,
tick_strike_cooldown,
Expand Down

0 comments on commit f195702

Please sign in to comment.