mirror of
https://github.com/kristoferssolo/maze-ascension.git
synced 2025-10-21 19:20:34 +00:00
feat(vfx): add movement sound
This commit is contained in:
parent
6685e3e2c9
commit
fea57af6d1
@ -53,7 +53,7 @@ impl Plugin for AppPlugin {
|
||||
})
|
||||
.set(AudioPlugin {
|
||||
global_volume: GlobalVolume {
|
||||
volume: Volume::new(0.3),
|
||||
volume: Volume::new(0.2),
|
||||
},
|
||||
..default()
|
||||
}),
|
||||
|
||||
@ -17,3 +17,32 @@ pub(super) fn blue_material() -> StandardMaterial {
|
||||
..default()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource, Asset, Reflect, Clone)]
|
||||
pub struct PlayerAssets {
|
||||
// This #[dependency] attribute marks the field as a dependency of the Asset.
|
||||
// This means that it will not finish loading until the labeled asset is also loaded.
|
||||
#[dependency]
|
||||
pub steps: Vec<Handle<AudioSource>>,
|
||||
}
|
||||
|
||||
impl PlayerAssets {
|
||||
pub const PATH_STEP_1: &str = "audio/sound_effects/step1.ogg";
|
||||
pub const PATH_STEP_2: &str = "audio/sound_effects/step2.ogg";
|
||||
pub const PATH_STEP_3: &str = "audio/sound_effects/step3.ogg";
|
||||
pub const PATH_STEP_4: &str = "audio/sound_effects/step4.ogg";
|
||||
}
|
||||
|
||||
impl FromWorld for PlayerAssets {
|
||||
fn from_world(world: &mut World) -> Self {
|
||||
let assets = world.resource::<AssetServer>();
|
||||
Self {
|
||||
steps: vec![
|
||||
assets.load(Self::PATH_STEP_1),
|
||||
assets.load(Self::PATH_STEP_2),
|
||||
assets.load(Self::PATH_STEP_3),
|
||||
assets.load(Self::PATH_STEP_4),
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,12 +4,16 @@ pub mod events;
|
||||
mod systems;
|
||||
mod triggers;
|
||||
|
||||
use assets::PlayerAssets;
|
||||
use bevy::{ecs::system::RunSystemOnce, prelude::*};
|
||||
use components::Player;
|
||||
use events::{DespawnPlayer, RespawnPlayer, SpawnPlayer};
|
||||
|
||||
use crate::asset_tracking::LoadResource;
|
||||
|
||||
pub(super) fn plugin(app: &mut App) {
|
||||
app.register_type::<Player>()
|
||||
.load_resource::<PlayerAssets>()
|
||||
.add_event::<SpawnPlayer>()
|
||||
.add_event::<RespawnPlayer>()
|
||||
.add_event::<DespawnPlayer>()
|
||||
|
||||
@ -1,14 +1,18 @@
|
||||
mod input;
|
||||
mod movement;
|
||||
pub mod setup;
|
||||
mod sound_effect;
|
||||
mod vertical_transition;
|
||||
|
||||
use crate::{screens::Screen, AppSet};
|
||||
use bevy::prelude::*;
|
||||
use input::player_input;
|
||||
use movement::player_movement;
|
||||
use sound_effect::play_movement_sound;
|
||||
use vertical_transition::handle_floor_transition;
|
||||
|
||||
use super::assets::PlayerAssets;
|
||||
|
||||
pub(super) fn plugin(app: &mut App) {
|
||||
app.add_systems(
|
||||
Update,
|
||||
@ -16,6 +20,10 @@ pub(super) fn plugin(app: &mut App) {
|
||||
player_input.in_set(AppSet::RecordInput),
|
||||
player_movement,
|
||||
handle_floor_transition.in_set(AppSet::RecordInput),
|
||||
(play_movement_sound)
|
||||
.chain()
|
||||
.run_if(resource_exists::<PlayerAssets>)
|
||||
.in_set(AppSet::Update),
|
||||
)
|
||||
.chain()
|
||||
.run_if(in_state(Screen::Gameplay)),
|
||||
|
||||
31
src/player/systems/sound_effect.rs
Normal file
31
src/player/systems/sound_effect.rs
Normal file
@ -0,0 +1,31 @@
|
||||
use crate::{
|
||||
audio::SoundEffect,
|
||||
player::{
|
||||
assets::PlayerAssets,
|
||||
components::{MovementTarget, Player},
|
||||
},
|
||||
};
|
||||
|
||||
use bevy::prelude::*;
|
||||
use rand::seq::SliceRandom;
|
||||
|
||||
pub fn play_movement_sound(
|
||||
mut commands: Commands,
|
||||
player_assets: Res<PlayerAssets>,
|
||||
moving_players: Query<&MovementTarget, (Changed<MovementTarget>, With<Player>)>,
|
||||
) {
|
||||
for movement_target in moving_players.iter() {
|
||||
if movement_target.is_none() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let rng = &mut rand::thread_rng();
|
||||
if let Some(random_step) = player_assets.steps.choose(rng) {
|
||||
commands.spawn((
|
||||
AudioPlayer(random_step.clone()),
|
||||
PlaybackSettings::DESPAWN,
|
||||
SoundEffect,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user