add crash sound on collision
This commit is contained in:
parent
c6b8d21c54
commit
c390a18ae5
|
@ -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:
|
||||
|
|
BIN
assets/sounds/crash.ogg
Normal file
BIN
assets/sounds/crash.ogg
Normal file
Binary file not shown.
16
src/actor.rs
16
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::<StartConversationEvent>();
|
||||
app.add_event::<SendMessageEvent>();
|
||||
|
@ -552,3 +554,17 @@ pub fn handle_chat_scripts(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_collisions(
|
||||
mut collision_event_reader: EventReader<Collision>,
|
||||
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
|
||||
q_player: Query<Entity, With<Player>>,
|
||||
) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<AudioSource>);
|
||||
#[derive(Resource)] pub struct SoundConnect(Handle<AudioSource>);
|
||||
#[derive(Resource)] pub struct SoundBikeStart(Handle<AudioSource>);
|
||||
#[derive(Resource)] pub struct SoundCrash(Handle<AudioSource>);
|
||||
|
||||
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<SoundPing>,
|
||||
sound_connect: Res<SoundConnect>,
|
||||
sound_bikestart: Res<SoundBikeStart>,
|
||||
sound_crash: Res<SoundCrash>,
|
||||
) {
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue