Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add striking sound #2

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading