add reaction wheel sound
This commit is contained in:
parent
1f79610476
commit
7b04a41177
|
@ -125,6 +125,7 @@ cargo run --release
|
|||
- 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
|
||||
- https://pixabay.com/sound-effects/electric-fan-motor-blades-removed-13169
|
||||
- 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/electricmotor.ogg
Normal file
BIN
assets/sounds/electricmotor.ogg
Normal file
Binary file not shown.
16
src/audio.rs
16
src/audio.rs
|
@ -1,5 +1,5 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy::audio::PlaybackMode;
|
||||
use bevy::audio::{PlaybackMode, Volume};
|
||||
use crate::settings;
|
||||
|
||||
const ASSET_CLICK: &str = "sounds/click-button-140881-crop.ogg";
|
||||
|
@ -14,6 +14,7 @@ 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";
|
||||
const ASSET_ELECTRICMOTOR: &str = "sounds/electricmotor.ogg";
|
||||
|
||||
pub struct AudioPlugin;
|
||||
impl Plugin for AudioPlugin {
|
||||
|
@ -44,6 +45,7 @@ pub enum Sfx {
|
|||
#[derive(Component)] pub struct ComponentThrusterSound;
|
||||
#[derive(Component)] pub struct ComponentRocketSound;
|
||||
#[derive(Component)] pub struct ComponentIonSound;
|
||||
#[derive(Component)] pub struct ComponentElectricMotorSound;
|
||||
#[derive(Component)] struct SoundBGM(Handle<AudioSource>);
|
||||
#[derive(Resource)] pub struct SoundClick(Handle<AudioSource>);
|
||||
#[derive(Resource)] pub struct SoundSwitch(Handle<AudioSource>);
|
||||
|
@ -110,6 +112,18 @@ pub fn setup(
|
|||
},
|
||||
},
|
||||
));
|
||||
commands.spawn((
|
||||
ComponentElectricMotorSound,
|
||||
AudioBundle {
|
||||
source: asset_server.load(ASSET_ELECTRICMOTOR),
|
||||
settings: PlaybackSettings {
|
||||
mode: PlaybackMode::Loop,
|
||||
volume: Volume::new(0.5),
|
||||
paused: true,
|
||||
..default()
|
||||
},
|
||||
},
|
||||
));
|
||||
commands.insert_resource(SoundClick(asset_server.load(ASSET_CLICK)));
|
||||
commands.insert_resource(SoundSwitch(asset_server.load(ASSET_SWITCH)));
|
||||
commands.insert_resource(SoundIncomingMessage(asset_server.load(ASSET_INCOMING_MESSAGE)));
|
||||
|
|
|
@ -129,6 +129,7 @@ fn apply_input_to_player(
|
|||
thruster_sound_controller: Query<&AudioSink, With<audio::ComponentThrusterSound>>,
|
||||
rocket_sound_controller: Query<&AudioSink, With<audio::ComponentRocketSound>>,
|
||||
ion_sound_controller: Query<&AudioSink, With<audio::ComponentIonSound>>,
|
||||
electricmotor_sound_controller: Query<&AudioSink, With<audio::ComponentElectricMotorSound>>,
|
||||
mut q_playercam: Query<(
|
||||
&mut Transform,
|
||||
&mut actor::Engine,
|
||||
|
@ -227,6 +228,7 @@ fn apply_input_to_player(
|
|||
}
|
||||
|
||||
// Handle mouse input and mouse-like key bindings
|
||||
let mut play_reactionwheel_sound = false;
|
||||
let mut mouse_delta = Vec2::ZERO;
|
||||
let mut pitch_yaw_rot = Vec3::ZERO;
|
||||
let mouseless_sensitivity = 8.0;
|
||||
|
@ -260,12 +262,32 @@ fn apply_input_to_player(
|
|||
}
|
||||
}
|
||||
if pitch_yaw_rot.length_squared() > 0.0001 {
|
||||
play_reactionwheel_sound = true;
|
||||
pitch_yaw_rot *= RADIANS_PER_DOT * settings.mouse_sensitivity;
|
||||
player_transform.rotation *= Quat::from_euler(EulerRot::ZYX,
|
||||
pitch_yaw_rot[2], pitch_yaw_rot[1], pitch_yaw_rot[0]).normalize();
|
||||
}
|
||||
|
||||
// Play sound effects
|
||||
if let Ok(sink) = electricmotor_sound_controller.get_single() {
|
||||
let volume = sink.volume();
|
||||
let max = (pitch_yaw_rot.length() * 10.0).clamp(0.2, 1.0);
|
||||
let max_speed = 1.0;
|
||||
let rise = 0.07;
|
||||
let fall = 0.15;
|
||||
if play_reactionwheel_sound {
|
||||
sink.set_volume((volume + rise).clamp(0.0, max));
|
||||
sink.set_speed((volume + rise).clamp(0.2, max * max_speed));
|
||||
sink.play()
|
||||
} else {
|
||||
if volume <= 0.01 {
|
||||
sink.pause()
|
||||
} else {
|
||||
sink.set_volume((volume - fall).clamp(0.0, max));
|
||||
sink.set_speed((volume - fall).clamp(0.2, max * max_speed));
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Ok(sink) = thruster_sound_controller.get_single() {
|
||||
if play_thruster_sound && engine.engine_type == actor::EngineType::Monopropellant {
|
||||
sink.play()
|
||||
|
|
Loading…
Reference in a new issue