Skip to content

Commit a5eb705

Browse files
authored
Merge pull request #2 from PraxTube/add-strike-sound
Add striking sound
2 parents 78b6bf3 + d1d8ad2 commit a5eb705

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

CREDITS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ https://grappe.itch.io/medal
5454

5555
### Sounds
5656

57+
#### Swing
58+
59+
- https://freesound.org/people/Eponn/sounds/547040/
60+
- https://freesound.org/people/spycrah/sounds/471097/
61+
- https://freesound.org/people/Artninja/sounds/700220/
62+
63+
Mixed by @TheYahton (https://github.com/PraxTube/insta-kill/issues/1)
64+
5765
### Music
5866

5967
https://shononoki.itch.io/bullet-hell-music-pack

assets/sounds/strike_sound.ogg

9.48 KB
Binary file not shown.

src/assets.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ pub struct GameAssets {
116116
#[asset(path = "music/bgm.ogg")]
117117
pub bgm: Handle<AudioSource>,
118118

119+
// --- SOUND ---
120+
#[asset(path = "sounds/strike_sound.ogg")]
121+
pub strike_sound: Handle<AudioSource>,
122+
119123
// --- FONT ---
120124
#[asset(path = "fonts/PressStart2P.ttf")]
121125
pub font: Handle<Font>,

src/audio/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
mod bgm;
22
mod sound;
33

4-
#[allow(unused_imports)]
54
pub use sound::PlaySound;
65

76
use bevy::prelude::*;

src/player/strike.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use bevy_rapier2d::prelude::*;
55
use bevy_trickfilm::prelude::*;
66

77
use crate::{
8+
audio::PlaySound,
89
utils::{quat_from_vec2, FixedRotation},
910
world::camera::YSort,
1011
GameAssets, GameState,
@@ -19,6 +20,8 @@ const OFFSET: Vec3 = Vec3::new(0.0, -10.0, 0.0);
1920
const CHAIN_COOLDOWN: f32 = 0.35;
2021
const STRIKE_COOLDOWN: f32 = 0.4;
2122
const STRIKE_CHAIN_COUNT: usize = 3;
23+
const SOUND_PITCH_CHANGE: f64 = 0.1;
24+
const SOUND_VOLUME: f64 = 0.7;
2225

2326
#[derive(Resource, Default)]
2427
struct StrikeCooldown {
@@ -120,6 +123,25 @@ fn despawn_strikes(
120123
}
121124
}
122125

126+
fn play_strike_sound(
127+
assets: Res<GameAssets>,
128+
mut ev_spawn_strike: EventReader<SpawnStrike>,
129+
mut ev_play_sound: EventWriter<PlaySound>,
130+
) {
131+
for ev in ev_spawn_strike.read() {
132+
// Lower playback_rate for the last (third) strike
133+
let playback_rate = if ev.strike_index == 2 { 1.0 } else { 1.5 };
134+
135+
ev_play_sound.send(PlaySound {
136+
clip: assets.strike_sound.clone(),
137+
volume: SOUND_VOLUME,
138+
rand_speed_intensity: SOUND_PITCH_CHANGE,
139+
playback_rate,
140+
..default()
141+
});
142+
}
143+
}
144+
123145
fn trigger_strike(
124146
player_input: Res<PlayerInput>,
125147
mouse_coords: Res<MouseWorldCoords>,
@@ -197,6 +219,7 @@ impl Plugin for PlayerStrikePlugin {
197219
(
198220
spawn_strikes,
199221
despawn_strikes,
222+
play_strike_sound,
200223
trigger_strike,
201224
reset_chain,
202225
tick_strike_cooldown,

0 commit comments

Comments
 (0)