diff --git a/assets/sounds/gasp.ogg b/assets/sounds/gasp.ogg new file mode 100644 index 0000000..7aca25f Binary files /dev/null and b/assets/sounds/gasp.ogg differ diff --git a/assets/sounds/gasprelief.ogg b/assets/sounds/gasprelief.ogg new file mode 100644 index 0000000..7faf6e7 Binary files /dev/null and b/assets/sounds/gasprelief.ogg differ diff --git a/src/audio.rs b/src/audio.rs index b03cea7..ecb2c08 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -23,6 +23,7 @@ impl Plugin for AudioPlugin { Update, ( play_zoom_sfx, + play_gasp_sfx, respawn_sinks.run_if(on_event::()), pause_all.run_if(on_event::()), ), @@ -64,6 +65,8 @@ const PATHS: &[(SfxType, Sfx, &str)] = &[ (SfxType::LoopSfx, Sfx::Ion, "sounds/ion.ogg"), (SfxType::LoopSfx, Sfx::Rocket, "sounds/rocket.ogg"), (SfxType::LoopSfx, Sfx::Thruster, "sounds/thruster.ogg"), + (SfxType::LoopSfx, Sfx::Gasp, "sounds/gasp.ogg"), + (SfxType::OneOff, Sfx::GaspRelief, "sounds/gasprelief.ogg"), (SfxType::OneOff, Sfx::Achieve, "sounds/achieve.ogg"), ( SfxType::OneOff, @@ -99,6 +102,8 @@ pub enum Sfx { Crash, ElectricMotor, EnterVehicle, + Gasp, + GaspRelief, IncomingChatMessage, Ion, Ping, @@ -272,6 +277,29 @@ pub fn play_zoom_sfx( } } +pub fn play_gasp_sfx( + player: Query<&actor::Suit, With>, + mut ew_sfx: EventWriter, + q_audiosinks: Query<(&audio::Sfx, &AudioSink)>, +) { + if let Ok(suit) = player.get_single() { + for (sfxtype, sink) in &q_audiosinks { + if *sfxtype != Sfx::Gasp { + continue; + } + if suit.oxygen <= 0.0 { + sink.set_volume(0.6); + sink.play(); + } else { + if !sink.is_paused() { + ew_sfx.send(PlaySfxEvent(Sfx::GaspRelief)); + sink.pause(); + } + } + } + } +} + pub fn pause_all(q_audiosinks: Query<&AudioSink, With>) { for sink in &q_audiosinks { sink.pause();