hit sounds and general sound effects sys

This commit is contained in:
2025-03-16 20:37:13 +01:00
parent 4fdd15d765
commit 7241f30094
10 changed files with 68 additions and 35 deletions

View File

@@ -1,6 +1,6 @@
use bevy::prelude::*;
use crate::{aim::AimState, npc::Hit};
use crate::{aim::AimState, npc::Hit, sounds::PlaySound};
#[derive(Event, Reflect)]
pub enum TriggerState {
@@ -12,17 +12,9 @@ pub fn plugin(app: &mut App) {
app.add_observer(on_trigger_state);
}
fn on_trigger_state(
trigger: Trigger<TriggerState>,
mut commands: Commands,
asset_server: Res<AssetServer>,
aim: Res<AimState>,
) {
fn on_trigger_state(trigger: Trigger<TriggerState>, mut commands: Commands, aim: Res<AimState>) {
if matches!(trigger.event(), TriggerState::Active) {
commands.spawn((
AudioPlayer::new(asset_server.load("sfx/abilities/gun.ogg")),
PlaybackSettings::DESPAWN,
));
commands.trigger(PlaySound::Gun);
if let Some(target) = aim.target {
commands.entity(target).trigger(Hit { damage: 20 });