add sound for ion engine

This commit is contained in:
yuni 2024-03-29 04:36:20 +01:00
parent 2b4fd9e5b5
commit 62abacf648
6 changed files with 26 additions and 2 deletions

BIN
assets/sounds/ion.ogg Normal file

Binary file not shown.

View file

@ -142,7 +142,7 @@ pub struct Vehicle;
pub enum EngineType { pub enum EngineType {
Monopropellant, Monopropellant,
Rocket, Rocket,
//Ion, Ion,
} }
#[derive(Component)] #[derive(Component)]

View file

@ -10,6 +10,7 @@ const ASSET_CONNECT: &str = "sounds/connect.ogg";
const ASSET_BGM: &str = "music/dead-space-style-ambient-music.ogg"; const ASSET_BGM: &str = "music/dead-space-style-ambient-music.ogg";
const ASSET_THRUSTER: &str = "sounds/thruster.ogg"; const ASSET_THRUSTER: &str = "sounds/thruster.ogg";
const ASSET_ROCKET: &str = "sounds/rocket.ogg"; const ASSET_ROCKET: &str = "sounds/rocket.ogg";
const ASSET_ION: &str = "sounds/ion.ogg";
//const ASSET_WAKEUP: &str = "sounds/wakeup.ogg"; //const ASSET_WAKEUP: &str = "sounds/wakeup.ogg";
const ASSET_BIKESTART: &str = "sounds/bikestart.ogg"; const ASSET_BIKESTART: &str = "sounds/bikestart.ogg";
@ -40,6 +41,7 @@ pub enum Sfx {
#[derive(Component)] pub struct ComponentBGM; #[derive(Component)] pub struct ComponentBGM;
#[derive(Component)] pub struct ComponentThrusterSound; #[derive(Component)] pub struct ComponentThrusterSound;
#[derive(Component)] pub struct ComponentRocketSound; #[derive(Component)] pub struct ComponentRocketSound;
#[derive(Component)] pub struct ComponentIonSound;
#[derive(Component)] struct SoundBGM(Handle<AudioSource>); #[derive(Component)] struct SoundBGM(Handle<AudioSource>);
#[derive(Resource)] pub struct SoundClick(Handle<AudioSource>); #[derive(Resource)] pub struct SoundClick(Handle<AudioSource>);
#[derive(Resource)] pub struct SoundSwitch(Handle<AudioSource>); #[derive(Resource)] pub struct SoundSwitch(Handle<AudioSource>);
@ -94,6 +96,17 @@ pub fn setup(
}, },
}, },
)); ));
commands.spawn((
ComponentIonSound,
AudioBundle {
source: asset_server.load(ASSET_ION),
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

@ -47,6 +47,7 @@ fn run_camera_controller(
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>>, rocket_sound_controller: Query<&AudioSink, With<audio::ComponentRocketSound>>,
ion_sound_controller: Query<&AudioSink, With<audio::ComponentIonSound>>,
mut q_engine: Query<&mut actor::Engine, With<actor::PlayerDrivesThis>>, mut q_engine: Query<&mut actor::Engine, With<actor::PlayerDrivesThis>>,
mut query: Query<( mut query: Query<(
&mut Transform, &mut Transform,
@ -181,5 +182,12 @@ fn run_camera_controller(
sink.pause() sink.pause()
} }
} }
if let Ok(sink) = ion_sound_controller.get_single() {
if play_thruster_sound && engine.engine_type == actor::EngineType::Ion {
sink.play()
} else {
sink.pause()
}
}
} }
} }

View file

@ -81,7 +81,7 @@ actor 10 -30 20 MeteorAceGT
scale 5 scale 5
vehicle yes vehicle yes
thrust 70 13.7 9.4 0.5 20 thrust 70 13.7 9.4 0.5 20
engine rocket engine ion
actor 10 0 70 suit actor 10 0 70 suit
name Icarus name Icarus

View file

@ -567,6 +567,9 @@ pub fn load_defs(
["engine", "rocket"] => { ["engine", "rocket"] => {
state.engine_type = actor::EngineType::Rocket; state.engine_type = actor::EngineType::Rocket;
} }
["engine", "ion"] => {
state.engine_type = actor::EngineType::Ion;
}
// Parsing chats // Parsing chats
["chat", chat_name] => { ["chat", chat_name] => {