Skip to content

Commit

Permalink
feat: Add git gud sound when demon boss kills you
Browse files Browse the repository at this point in the history
  • Loading branch information
PraxTube committed Dec 18, 2023
1 parent a0294de commit 0dbd84a
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 29 deletions.
Binary file modified assets/sounds/demon_boss_vocal_explosion.ogg
Binary file not shown.
Binary file added assets/sounds/gitgud.ogg
Binary file not shown.
2 changes: 2 additions & 0 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ pub struct GameAssets {
pub demon_boss_step_sound: Handle<AudioSource>,
#[asset(path = "sounds/demon_boss_vocal_explosion.ogg")]
pub demon_boss_vocal_explosion_sound: Handle<AudioSource>,
#[asset(path = "sounds/gitgud.ogg")]
pub git_gud: Handle<AudioSource>,

#[asset(path = "sounds/lightning_bird_flap.ogg")]
pub lightning_bird_flap_sound: Handle<AudioSource>,
Expand Down
42 changes: 39 additions & 3 deletions src/enemy/demon_boss/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use bevy::prelude::*;

use crate::{audio::PlaySound, GameAssets, GameState};

use super::{DemonBoss, DemonBossState};
use super::{
cast::{DemonSpell, DemonSpellCast},
DemonBoss, DemonBossState,
};

const TIME_BETWEEN_STEPS: f32 = 0.8;
const RAND_SPEED_INTENSITY: f64 = 0.2;
Expand Down Expand Up @@ -56,13 +59,46 @@ fn play_step_sounds(
});
}

fn play_cast_vocals(
assets: Res<GameAssets>,
q_demon_spells: Query<&DemonSpellCast, Added<DemonSpellCast>>,
mut play_sound: EventWriter<PlaySound>,
) {
for demon_spell in &q_demon_spells {
let vocals = match demon_spell.spell {
DemonSpell::Explosion => assets.demon_boss_vocal_explosion_sound.clone(),
};

play_sound.send(PlaySound {
clip: vocals,
..default()
});
}
}

fn play_git_gud(
assets: Res<GameAssets>,
q_demon_boss: Query<&DemonBoss>,
mut play_sound: EventWriter<PlaySound>,
) {
if q_demon_boss.is_empty() {
return;
}

play_sound.send(PlaySound {
clip: assets.git_gud.clone(),
..default()
});
}

pub struct DemonBossAudioPlugin;

impl Plugin for DemonBossAudioPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
Update,
(play_step_sounds, tick_timers).run_if(in_state(GameState::Gaming)),
);
(play_step_sounds, play_cast_vocals, tick_timers).run_if(in_state(GameState::Gaming)),
)
.add_systems(OnEnter(GameState::GameOver), play_git_gud);
}
}
22 changes: 2 additions & 20 deletions src/enemy/demon_boss/cast.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy::prelude::*;

use super::{state::DemonBossState, DemonBoss};
use crate::{audio::PlaySound, GameAssets, GameState};
use crate::GameState;

#[derive(Clone, PartialEq)]
pub enum DemonSpell {
Expand Down Expand Up @@ -40,23 +40,6 @@ fn spawn_demon_spell(
});
}

fn play_cast_vocals(
assets: Res<GameAssets>,
q_demon_spells: Query<&DemonSpellCast, Added<DemonSpellCast>>,
mut play_sound: EventWriter<PlaySound>,
) {
for demon_spell in &q_demon_spells {
let vocals = match demon_spell.spell {
DemonSpell::Explosion => assets.demon_boss_vocal_explosion_sound.clone(),
};

play_sound.send(PlaySound {
clip: vocals,
..default()
});
}
}

fn relay_demon_spells(
mut commands: Commands,
time: Res<Time>,
Expand All @@ -78,8 +61,7 @@ impl Plugin for DemonBossCastPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
Update,
(spawn_demon_spell, relay_demon_spells, play_cast_vocals)
.run_if(in_state(GameState::Gaming)),
(spawn_demon_spell, relay_demon_spells).run_if(in_state(GameState::Gaming)),
)
.add_event::<SpawnDemonSpell>();
}
Expand Down
2 changes: 1 addition & 1 deletion src/enemy/demon_boss/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub struct DemonBoss {
impl Default for DemonBoss {
fn default() -> Self {
Self {
damage: 1.0,
damage: 999.0,
state: DemonBossState::Idling,
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/enemy/demon_boss/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ fn spawn_demon_boss(mut commands: Commands, assets: Res<GameAssets>) {
YSort(36.0 * SCALE * TRANSLATION_TO_PIXEL),
SpriteSheetBundle {
texture_atlas: assets.enemy_boss.clone(),
transform: Transform::from_translation(PLAYER_SPAWN_POS)
.with_scale(Vec3::splat(SCALE)),
transform: Transform::from_translation(
PLAYER_SPAWN_POS - Vec3::new(0.0, 100.0, 0.0),
)
.with_scale(Vec3::splat(SCALE)),
..default()
},
))
Expand Down
4 changes: 1 addition & 3 deletions src/enemy/demon_boss/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ fn switch_state(
Err(_) => return,
};

if demon_boss.state == DemonBossState::Striking {
return;
} else if demon_boss.state == DemonBossState::Casting {
if demon_boss.state == DemonBossState::Striking || demon_boss.state == DemonBossState::Casting {
return;
}

Expand Down

0 comments on commit 0dbd84a

Please sign in to comment.