add rocket sound effect for bike

This commit is contained in:
yuni 2024-03-28 14:10:10 +01:00
parent cc285a7548
commit f4aea80f34
7 changed files with 39 additions and 3 deletions

View file

@ -69,6 +69,7 @@ More information here: https://bevy-cheatbook.github.io/setup/cross/linux-window
- https://pixabay.com/sound-effects/click-button-140881 - https://pixabay.com/sound-effects/click-button-140881
- https://pixabay.com/sound-effects/data-transmission-sound-from-14664-72309 - https://pixabay.com/sound-effects/data-transmission-sound-from-14664-72309
- https://pixabay.com/sound-effects/thrusters-loopwav-14699 - https://pixabay.com/sound-effects/thrusters-loopwav-14699
- https://pixabay.com/sound-effects/rocket-loop-99748
- Star chart based on the [HYG Stellar database](https://github.com/astronexus/HYG-Database) - Star chart based on the [HYG Stellar database](https://github.com/astronexus/HYG-Database)
- Custom font Yupiter is based on: - Custom font Yupiter is based on:
- Noto Sans Symbols 2, Copyright 2022 The Noto Project Authors (https://github.com/notofonts/symbols) - Noto Sans Symbols 2, Copyright 2022 The Noto Project Authors (https://github.com/notofonts/symbols)

BIN
assets/sounds/rocket.ogg Normal file

Binary file not shown.

View file

@ -125,12 +125,20 @@ impl Default for LifeForm { fn default() -> Self { Self {
#[derive(Component)] #[derive(Component)]
pub struct Vehicle; pub struct Vehicle;
#[derive(Copy, Clone, PartialEq)]
pub enum EngineType {
Monopropellant,
Rocket,
//Ion,
}
#[derive(Component)] #[derive(Component)]
pub struct Engine { pub struct Engine {
pub thrust_forward: f32, pub thrust_forward: f32,
pub thrust_back: f32, pub thrust_back: f32,
pub thrust_sideways: f32, pub thrust_sideways: f32,
pub reaction_wheels: f32, pub reaction_wheels: f32,
pub engine_type: EngineType,
} }
impl Default for Engine { impl Default for Engine {
fn default() -> Self { fn default() -> Self {
@ -139,6 +147,7 @@ impl Default for Engine {
thrust_back: 1.0, thrust_back: 1.0,
thrust_sideways: 1.0, thrust_sideways: 1.0,
reaction_wheels: 1.0, reaction_wheels: 1.0,
engine_type: EngineType::Monopropellant,
} }
} }
} }

View file

@ -10,6 +10,7 @@ const ASSET_CONNECT: &str = "sounds/connect.ogg";
const ASSET_RADIO: &str = "external/LP - Girls Go Wild (Official Music Video) [M7XRN0oHGIM].mp3"; const ASSET_RADIO: &str = "external/LP - Girls Go Wild (Official Music Video) [M7XRN0oHGIM].mp3";
const ASSET_BGM: &str = "external/Ben Prunty - FTL - 12 Void (Explore).mp3"; const ASSET_BGM: &str = "external/Ben Prunty - FTL - 12 Void (Explore).mp3";
const ASSET_THRUSTER: &str = "sounds/thruster.ogg"; const ASSET_THRUSTER: &str = "sounds/thruster.ogg";
const ASSET_ROCKET: &str = "sounds/rocket.ogg";
const ASSET_WAKEUP: &str = "sounds/wakeup.ogg"; const ASSET_WAKEUP: &str = "sounds/wakeup.ogg";
pub struct AudioPlugin; pub struct AudioPlugin;
@ -39,6 +40,7 @@ pub enum Sfx {
#[derive(Component)] pub struct ComponentBGM; #[derive(Component)] pub struct ComponentBGM;
#[derive(Component)] pub struct ComponentRadio; #[derive(Component)] pub struct ComponentRadio;
#[derive(Component)] pub struct ComponentThrusterSound; #[derive(Component)] pub struct ComponentThrusterSound;
#[derive(Component)] pub struct ComponentRocketSound;
#[derive(Component)] struct SoundBGM(Handle<AudioSource>); #[derive(Component)] struct SoundBGM(Handle<AudioSource>);
#[derive(Component)] pub struct SoundRadio(Handle<AudioSource>); #[derive(Component)] pub struct SoundRadio(Handle<AudioSource>);
#[derive(Resource)] pub struct SoundClick(Handle<AudioSource>); #[derive(Resource)] pub struct SoundClick(Handle<AudioSource>);
@ -93,6 +95,17 @@ pub fn setup(
}, },
}, },
)); ));
commands.spawn((
ComponentRocketSound,
AudioBundle {
source: asset_server.load(ASSET_ROCKET),
settings: PlaybackSettings {
mode: PlaybackMode::Loop,
paused: true,
..default()
},
},
));
commands.insert_resource(SoundClick(asset_server.load(ASSET_CLICK))); commands.insert_resource(SoundClick(asset_server.load(ASSET_CLICK)));
commands.insert_resource(SoundSwitch(asset_server.load(ASSET_SWITCH))); commands.insert_resource(SoundSwitch(asset_server.load(ASSET_SWITCH)));
commands.insert_resource(SoundIncomingMessage(asset_server.load(ASSET_INCOMING_MESSAGE))); commands.insert_resource(SoundIncomingMessage(asset_server.load(ASSET_INCOMING_MESSAGE)));

View file

@ -52,6 +52,7 @@ fn run_camera_controller(
mut mouse_events: EventReader<MouseMotion>, mut mouse_events: EventReader<MouseMotion>,
key_input: Res<ButtonInput<KeyCode>>, key_input: Res<ButtonInput<KeyCode>>,
thruster_sound_controller: Query<&AudioSink, With<audio::ComponentThrusterSound>>, thruster_sound_controller: Query<&AudioSink, With<audio::ComponentThrusterSound>>,
rocket_sound_controller: Query<&AudioSink, With<audio::ComponentRocketSound>>,
q_engine: Query<&actor::Engine, With<actor::PlayerDrivesThis>>, q_engine: Query<&actor::Engine, With<actor::PlayerDrivesThis>>,
mut query: Query<(&mut Transform, &mut CameraController, &mut actor::Actor, &actor::Engine), With<Camera>>, mut query: Query<(&mut Transform, &mut CameraController, &mut actor::Actor, &actor::Engine), With<Camera>>,
) { ) {
@ -156,7 +157,14 @@ fn run_camera_controller(
} }
if let Ok(sink) = thruster_sound_controller.get_single() { if let Ok(sink) = thruster_sound_controller.get_single() {
if play_thruster_sound { if play_thruster_sound && engine.engine_type == actor::EngineType::Monopropellant {
sink.play()
} else {
sink.pause()
}
}
if let Ok(sink) = rocket_sound_controller.get_single() {
if play_thruster_sound && engine.engine_type == actor::EngineType::Rocket {
sink.play() sink.play()
} else { } else {
sink.pause() sink.pause()

View file

@ -81,6 +81,7 @@ actor 10 -30 20 bike
scale 5 scale 5
vehicle yes vehicle yes
thrust 50 0 10 0.5 thrust 50 0 10 0.5
engine rocket
actor 10 0 70 suit actor 10 0 70 suit
name Icarus name Icarus

View file

@ -215,14 +215,12 @@ pub fn setup(
}); });
} }
#[derive(Debug)]
enum DefClass { enum DefClass {
Actor, Actor,
Chat, Chat,
None, None,
} }
#[derive(Debug)]
struct ParserState { struct ParserState {
class: DefClass, class: DefClass,
@ -246,6 +244,7 @@ struct ParserState {
thrust_sideways: f32, thrust_sideways: f32,
thrust_back: f32, thrust_back: f32,
reaction_wheels: f32, reaction_wheels: f32,
engine_type: actor::EngineType,
oxygen: f32, oxygen: f32,
// Chat fields // Chat fields
@ -284,6 +283,7 @@ impl Default for ParserState {
thrust_sideways: default_engine.thrust_forward, thrust_sideways: default_engine.thrust_forward,
thrust_back: default_engine.thrust_back, thrust_back: default_engine.thrust_back,
reaction_wheels: default_engine.reaction_wheels, reaction_wheels: default_engine.reaction_wheels,
engine_type: default_engine.engine_type,
oxygen: nature::OXY_D, oxygen: nature::OXY_D,
delay: 0.0, delay: 0.0,
@ -357,6 +357,7 @@ impl ParserState {
thrust_back: self.thrust_back, thrust_back: self.thrust_back,
thrust_sideways: self.thrust_sideways, thrust_sideways: self.thrust_sideways,
reaction_wheels: self.reaction_wheels, reaction_wheels: self.reaction_wheels,
engine_type: self.engine_type,
}; };
let component_suit = actor::Suit { let component_suit = actor::Suit {
oxygen: self.oxygen, oxygen: self.oxygen,
@ -557,6 +558,9 @@ pub fn load_defs(
state.reaction_wheels = reaction_wheels_float; state.reaction_wheels = reaction_wheels_float;
} }
} }
["engine", "rocket"] => {
state.engine_type = actor::EngineType::Rocket;
}
// Parsing chats // Parsing chats
["chat", chat_name] => { ["chat", chat_name] => {