From 7539abb332cc398ec8a5d5cb30a20b0d7b40f519 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Mon, 25 Dec 2023 13:29:53 -0600 Subject: [PATCH] Sound plays, but spatial-ness is borked --- Cargo.lock | 7 +++++++ Cargo.toml | 2 +- src/main.rs | 3 ++- src/player.rs | 23 +++++++++++++++++++---- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ea3113a..88ebcba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1963,6 +1963,12 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" +[[package]] +name = "hound" +version = "3.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62adaabb884c94955b19907d60019f4e145d091c75345379e70d1ee696f7854f" + [[package]] name = "image" version = "0.24.7" @@ -2891,6 +2897,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b1bb7b48ee48471f55da122c0044fcc7600cfcc85db88240b89cb832935e611" dependencies = [ "cpal", + "hound", "lewton", ] diff --git a/Cargo.toml b/Cargo.toml index 19d8ab2..8020811 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy = { version = "0.12.1", features = ["wayland"] } +bevy = { version = "0.12.1", features = ["wayland", "wav"] } # bevy = { version = "0.12.1", features = ["wayland", "file_watcher", "trace"] } [profile.dev] diff --git a/src/main.rs b/src/main.rs index 4b8a04d..9eb0369 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use bevy::audio::{AudioPlugin, SpatialScale}; +use bevy::audio::{AudioPlugin, SpatialScale, VolumeLevel}; use bevy::prelude::*; mod assets; @@ -22,6 +22,7 @@ fn main() { }) .set(AudioPlugin { spatial_scale: SpatialScale::new_2d(100.), + global_volume: GlobalVolume::new(100.), ..default() }) .set(ImagePlugin::default_nearest()), diff --git a/src/player.rs b/src/player.rs index c834615..8e26860 100644 --- a/src/player.rs +++ b/src/player.rs @@ -18,7 +18,7 @@ impl Plugin for Player { } fn spawn_player(mut commands: Commands, assets: Res) { - let listener = SpatialListener::new(0.); + let listener = SpatialListener::new(1.); commands .spawn(( @@ -40,14 +40,29 @@ fn spawn_player(mut commands: Commands, assets: Res) { } fn controls( - mut query: Query<(&mut TextureAtlasSprite, &mut Heading), With>, + mut commands: Commands, + mut query: Query<(&mut TextureAtlasSprite, &mut Heading, Entity), With>, input: Res>, + assets: Res, ) { - let (mut sprite, mut heading) = query.single_mut(); + let (mut sprite, mut heading, player_entity) = query.single_mut(); **heading = Vec2::ZERO; + for key in input.get_just_pressed() { + match key { + KeyCode::Space => { + let child = commands + .spawn(AudioSourceBundle { + source: assets.sounds.meow.clone(), + settings: PlaybackSettings::DESPAWN.with_spatial(true), + }) + .id(); + commands.entity(player_entity).push_children(&[child]); + } + _ => {} + } + } for key in input.get_pressed() { match key { - KeyCode::Space => {} KeyCode::A | KeyCode::Left => { **heading -= Vec2::X; }