diff --git a/README.md b/README.md index e63ec11..fcaaf3d 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ More information here: https://bevy-cheatbook.github.io/setup/cross/linux-window - https://pixabay.com/sound-effects/electricity-6353 - https://pixabay.com/sound-effects/ducati-696-monster-33217 - https://pixabay.com/sound-effects/high-energy-humming-195612 +- https://pixabay.com/sound-effects/box-crash-106687 - Music: [Dead Space Style Ambient Music](https://pixabay.com/music/ambient-dead-space-style-ambient-music-184793) by [Sharvarian](https://www.fiverr.com/sharvarian) - Star chart based on the [HYG Stellar database](https://github.com/astronexus/HYG-Database) - Custom font Yupiter is based on: diff --git a/assets/sounds/crash.ogg b/assets/sounds/crash.ogg new file mode 100644 index 0000000..378c8af Binary files /dev/null and b/assets/sounds/crash.ogg differ diff --git a/src/actor.rs b/src/actor.rs index 067d7dd..71848ca 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -1,4 +1,5 @@ use bevy::prelude::*; +use bevy_xpbd_3d::prelude::*; use crate::{nature, settings, actor, audio, hud}; pub const ENGINE_SPEED_FACTOR: f32 = 30.0; @@ -19,6 +20,7 @@ impl Plugin for ActorPlugin { handle_input, handle_chat_scripts, handle_vehicle_enter_exit, + handle_collisions, )); app.add_event::(); app.add_event::(); @@ -552,3 +554,17 @@ pub fn handle_chat_scripts( } } } + +fn handle_collisions( + mut collision_event_reader: EventReader, + mut ew_sfx: EventWriter, + q_player: Query>, +) { + if let Ok(player) = q_player.get_single() { + for Collision(contacts) in collision_event_reader.read() { + if contacts.entity1 == player || contacts.entity2 == player { + ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Crash)); + } + } + } +} diff --git a/src/audio.rs b/src/audio.rs index d582945..f3bb309 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -13,6 +13,7 @@ const ASSET_ROCKET: &str = "sounds/rocket.ogg"; const ASSET_ION: &str = "sounds/ion.ogg"; //const ASSET_WAKEUP: &str = "sounds/wakeup.ogg"; const ASSET_BIKESTART: &str = "sounds/bikestart.ogg"; +const ASSET_CRASH: &str = "sounds/crash.ogg"; pub struct AudioPlugin; impl Plugin for AudioPlugin { @@ -33,6 +34,7 @@ pub enum Sfx { Ping, Connect, EnterVehicle, + Crash, None, } @@ -49,6 +51,7 @@ pub enum Sfx { #[derive(Resource)] pub struct SoundPing(Handle); #[derive(Resource)] pub struct SoundConnect(Handle); #[derive(Resource)] pub struct SoundBikeStart(Handle); +#[derive(Resource)] pub struct SoundCrash(Handle); pub fn setup( mut commands: Commands, @@ -113,6 +116,7 @@ pub fn setup( commands.insert_resource(SoundPing(asset_server.load(ASSET_PING))); commands.insert_resource(SoundConnect(asset_server.load(ASSET_CONNECT))); commands.insert_resource(SoundBikeStart(asset_server.load(ASSET_BIKESTART))); + commands.insert_resource(SoundCrash(asset_server.load(ASSET_CRASH))); } pub fn toggle_bgm( @@ -143,6 +147,7 @@ pub fn play_sfx( sound_ping: Res, sound_connect: Res, sound_bikestart: Res, + sound_crash: Res, ) { if settings.mute_sfx && !events_sfx.is_empty() { events_sfx.clear(); @@ -160,6 +165,7 @@ pub fn play_sfx( Sfx::Ping => sound_ping.0.clone(), Sfx::Connect => sound_connect.0.clone(), Sfx::EnterVehicle => sound_bikestart.0.clone(), + Sfx::Crash => sound_crash.0.clone(), Sfx::None => sound_ping.0.clone(), }, settings: PlaybackSettings::DESPAWN, @@ -175,6 +181,7 @@ pub fn str2sfx(sfx_label: &str) -> Sfx { "ping" => Sfx::Ping, "connect" => Sfx::Connect, "entervehicle" => Sfx::EnterVehicle, + "crash" => Sfx::Crash, _ => Sfx::None, }; } diff --git a/src/camera.rs b/src/camera.rs index 623db67..33fd0f1 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -81,7 +81,14 @@ fn run_camera_controller( return; } - angularvelocity.0 = Vec3::splat(0.0); + if angularvelocity.length_squared() > 0.0001 { + angularvelocity.x *= 0.98; + angularvelocity.y *= 0.98; + angularvelocity.z *= 0.98; + } + else { + angularvelocity.0 = Vec3::splat(0.0); + } // Handle key input let mut axis_input = Vec3::ZERO;