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 Jun 13, 2024
1 parent 78b6bf3 commit d1d8ad2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ 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/

Mixed by @TheYahton (https://github.com/PraxTube/insta-kill/issues/1)

### 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
23 changes: 23 additions & 0 deletions src/player/strike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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 +20,8 @@ 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;
const SOUND_VOLUME: f64 = 0.7;

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

fn play_strike_sound(
assets: Res<GameAssets>,
mut ev_spawn_strike: EventReader<SpawnStrike>,
mut ev_play_sound: EventWriter<PlaySound>,
) {
for ev in ev_spawn_strike.read() {
// Lower playback_rate for the last (third) strike
let playback_rate = if ev.strike_index == 2 { 1.0 } else { 1.5 };

ev_play_sound.send(PlaySound {
clip: assets.strike_sound.clone(),
volume: SOUND_VOLUME,
rand_speed_intensity: SOUND_PITCH_CHANGE,
playback_rate,
..default()
});
}
}

fn trigger_strike(
player_input: Res<PlayerInput>,
mouse_coords: Res<MouseWorldCoords>,
Expand Down Expand Up @@ -197,6 +219,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 d1d8ad2

Please sign in to comment.