sound effects of reloading

This commit is contained in:
2025-04-02 02:22:12 +08:00
parent 01f8128e5f
commit f967b1b0da
6 changed files with 13 additions and 2 deletions

BIN
assets/sfx/ui/invalid.ogg Normal file

Binary file not shown.

BIN
assets/sfx/ui/reloaded.ogg Normal file

Binary file not shown.

View File

@@ -6,6 +6,7 @@ use crate::{
heads::ActiveHeads, heads::ActiveHeads,
npc::Hit, npc::Hit,
player::{Player, PlayerRig}, player::{Player, PlayerRig},
sounds::PlaySound,
tb_entities::EnemySpawn, tb_entities::EnemySpawn,
}; };
use avian3d::prelude::*; use avian3d::prelude::*;
@@ -90,7 +91,7 @@ fn on_trigger_state(
}; };
if !state.has_ammo() { if !state.has_ammo() {
//TOOD: play sound commands.trigger(PlaySound::Invalid);
return; return;
} }

View File

@@ -133,7 +133,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.insert_resource(HeadsImages { heads }); commands.insert_resource(HeadsImages { heads });
} }
fn reload(mut active: ResMut<ActiveHeads>, time: Res<Time>) { fn reload(mut commands: Commands, mut active: ResMut<ActiveHeads>, time: Res<Time>) {
if !active.reloading() { if !active.reloading() {
return; return;
} }
@@ -144,6 +144,7 @@ fn reload(mut active: ResMut<ActiveHeads>, time: Res<Time>) {
}; };
if !head.has_ammo() && (head.last_use + head.reload_duration <= time.elapsed_secs()) { if !head.has_ammo() && (head.last_use + head.reload_duration <= time.elapsed_secs()) {
commands.trigger(PlaySound::Reloaded);
head.ammo = head.ammo_max; head.ammo = head.ammo_max;
} }
} }

View File

@@ -19,6 +19,11 @@ pub struct AudioAssets {
#[asset(path = "sfx/ui/selection.ogg")] #[asset(path = "sfx/ui/selection.ogg")]
pub selection: Handle<AudioSource>, pub selection: Handle<AudioSource>,
#[asset(path = "sfx/ui/invalid.ogg")]
pub invalid: Handle<AudioSource>,
#[asset(path = "sfx/ui/reloaded.ogg")]
pub reloaded: Handle<AudioSource>,
#[asset(path = "sfx/abilities/throw.ogg")] #[asset(path = "sfx/abilities/throw.ogg")]
pub throw: Handle<AudioSource>, pub throw: Handle<AudioSource>,
#[asset(path = "sfx/abilities/throw-explosion.ogg")] #[asset(path = "sfx/abilities/throw-explosion.ogg")]

View File

@@ -11,6 +11,8 @@ pub enum PlaySound {
Gate, Gate,
CashCollect, CashCollect,
Selection, Selection,
Invalid,
Reloaded,
Backpack { open: bool }, Backpack { open: bool },
Head(String), Head(String),
} }
@@ -44,6 +46,8 @@ fn spawn_sounds(
PlaySound::Selection => assets.selection.clone(), PlaySound::Selection => assets.selection.clone(),
PlaySound::Throw => assets.throw.clone(), PlaySound::Throw => assets.throw.clone(),
PlaySound::ThrowHit => assets.throw_explosion.clone(), PlaySound::ThrowHit => assets.throw_explosion.clone(),
PlaySound::Reloaded => assets.reloaded.clone(),
PlaySound::Invalid => assets.invalid.clone(),
PlaySound::Backpack { open } => { PlaySound::Backpack { open } => {
if *open { if *open {
assets.backpack_open.clone() assets.backpack_open.clone()