start music & sound
This commit is contained in:
parent
d168e48759
commit
061e311cf6
12 changed files with 215 additions and 6 deletions
164
Cargo.lock
generated
164
Cargo.lock
generated
|
|
@ -167,6 +167,12 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61"
|
||||
|
||||
[[package]]
|
||||
name = "approx"
|
||||
version = "0.5.1"
|
||||
|
|
@ -283,6 +289,12 @@ dependencies = [
|
|||
"portable-atomic",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atomic-arena"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73e8ed45f88ed32e6827a96b62d8fd4086d72defc754c5c6bd08470c1aaf648e"
|
||||
|
||||
[[package]]
|
||||
name = "atomic-waker"
|
||||
version = "1.1.2"
|
||||
|
|
@ -328,6 +340,7 @@ name = "bevy-santa"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bevy",
|
||||
"bevy_kira_audio",
|
||||
"derive_more",
|
||||
"rand",
|
||||
]
|
||||
|
|
@ -869,6 +882,23 @@ dependencies = [
|
|||
"bevy_winit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bevy_kira_audio"
|
||||
version = "0.24.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1acdb4b9d888db21100e52ad6276307fcb2e1d0ef51b7eb529c3ffe74179a5bd"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bevy",
|
||||
"bevy_math",
|
||||
"glam 0.25.0",
|
||||
"kira",
|
||||
"mint",
|
||||
"parking_lot",
|
||||
"thiserror 2.0.17",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bevy_light"
|
||||
version = "0.17.3"
|
||||
|
|
@ -930,7 +960,7 @@ dependencies = [
|
|||
"approx",
|
||||
"bevy_reflect",
|
||||
"derive_more",
|
||||
"glam",
|
||||
"glam 0.30.9",
|
||||
"itertools 0.14.0",
|
||||
"libm",
|
||||
"rand",
|
||||
|
|
@ -1105,7 +1135,7 @@ dependencies = [
|
|||
"downcast-rs 2.0.2",
|
||||
"erased-serde",
|
||||
"foldhash 0.2.0",
|
||||
"glam",
|
||||
"glam 0.30.9",
|
||||
"inventory",
|
||||
"petgraph",
|
||||
"serde",
|
||||
|
|
@ -2123,7 +2153,7 @@ checksum = "02ba239319a4f60905966390f5e52799d868103a533bb7e27822792332504ddd"
|
|||
dependencies = [
|
||||
"const_panic",
|
||||
"encase_derive",
|
||||
"glam",
|
||||
"glam 0.30.9",
|
||||
"thiserror 2.0.17",
|
||||
]
|
||||
|
||||
|
|
@ -2147,6 +2177,15 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encoding_rs"
|
||||
version = "0.8.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.2"
|
||||
|
|
@ -2421,6 +2460,12 @@ dependencies = [
|
|||
"xml-rs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glam"
|
||||
version = "0.25.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "151665d9be52f9bb40fc7966565d39666f2d1e69233571b71b87791c7e0528b3"
|
||||
|
||||
[[package]]
|
||||
name = "glam"
|
||||
version = "0.30.9"
|
||||
|
|
@ -2429,6 +2474,7 @@ checksum = "bd47b05dddf0005d850e5644cae7f2b14ac3df487979dbfff3b56f20b1a6ae46"
|
|||
dependencies = [
|
||||
"bytemuck",
|
||||
"libm",
|
||||
"mint",
|
||||
"rand",
|
||||
"serde_core",
|
||||
]
|
||||
|
|
@ -2628,7 +2674,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "29a164ceff4500f2a72b1d21beaa8aa8ad83aec2b641844c659b190cb3ea2e0b"
|
||||
dependencies = [
|
||||
"constgebra",
|
||||
"glam",
|
||||
"glam 0.30.9",
|
||||
"tinyvec",
|
||||
]
|
||||
|
||||
|
|
@ -2791,6 +2837,23 @@ version = "3.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
|
||||
|
||||
[[package]]
|
||||
name = "kira"
|
||||
version = "0.10.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e7f96b236a2d8b1ecebcd0e4e81462405392699e261f852cf930ea150f15abd"
|
||||
dependencies = [
|
||||
"atomic-arena",
|
||||
"cpal",
|
||||
"glam 0.30.9",
|
||||
"mint",
|
||||
"paste",
|
||||
"rtrb",
|
||||
"send_wrapper",
|
||||
"symphonia",
|
||||
"triple_buffer",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ktx2"
|
||||
version = "0.4.0"
|
||||
|
|
@ -2966,6 +3029,12 @@ dependencies = [
|
|||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mint"
|
||||
version = "0.5.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e53debba6bda7a793e5f99b8dacf19e626084f525f7829104ba9898f367d85ff"
|
||||
|
||||
[[package]]
|
||||
name = "moxcms"
|
||||
version = "0.7.11"
|
||||
|
|
@ -3867,6 +3936,12 @@ version = "0.20.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c20b6793b5c2fa6553b250154b78d6d0db37e72700ae35fad9387a46f487c97"
|
||||
|
||||
[[package]]
|
||||
name = "rtrb"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad8388ea1a9e0ea807e442e8263a699e7edcb320ecbcd21b4fa8ff859acce3ba"
|
||||
|
||||
[[package]]
|
||||
name = "rustc-hash"
|
||||
version = "1.1.0"
|
||||
|
|
@ -4195,6 +4270,77 @@ dependencies = [
|
|||
"zeno",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "symphonia"
|
||||
version = "0.5.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5773a4c030a19d9bfaa090f49746ff35c75dfddfa700df7a5939d5e076a57039"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"symphonia-codec-vorbis",
|
||||
"symphonia-core",
|
||||
"symphonia-format-ogg",
|
||||
"symphonia-metadata",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "symphonia-codec-vorbis"
|
||||
version = "0.5.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f025837c309cd69ffef572750b4a2257b59552c5399a5e49707cc5b1b85d1c73"
|
||||
dependencies = [
|
||||
"log",
|
||||
"symphonia-core",
|
||||
"symphonia-utils-xiph",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "symphonia-core"
|
||||
version = "0.5.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ea00cc4f79b7f6bb7ff87eddc065a1066f3a43fe1875979056672c9ef948c2af"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bitflags 1.3.2",
|
||||
"bytemuck",
|
||||
"lazy_static",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "symphonia-format-ogg"
|
||||
version = "0.5.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b4955c67c1ed3aa8ae8428d04ca8397fbef6a19b2b051e73b5da8b1435639cb"
|
||||
dependencies = [
|
||||
"log",
|
||||
"symphonia-core",
|
||||
"symphonia-metadata",
|
||||
"symphonia-utils-xiph",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "symphonia-metadata"
|
||||
version = "0.5.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "36306ff42b9ffe6e5afc99d49e121e0bd62fe79b9db7b9681d48e29fa19e6b16"
|
||||
dependencies = [
|
||||
"encoding_rs",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"symphonia-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "symphonia-utils-xiph"
|
||||
version = "0.5.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee27c85ab799a338446b68eec77abf42e1a6f1bb490656e121c6e27bfbab9f16"
|
||||
dependencies = [
|
||||
"symphonia-core",
|
||||
"symphonia-metadata",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.111"
|
||||
|
|
@ -4453,6 +4599,15 @@ dependencies = [
|
|||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "triple_buffer"
|
||||
version = "8.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "420466259f9fa5decc654c490b9ab538400e5420df8237f84ecbe20368bcf72b"
|
||||
dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ttf-parser"
|
||||
version = "0.20.0"
|
||||
|
|
@ -4557,6 +4712,7 @@ checksum = "e2e054861b4bd027cd373e18e8d8d8e6548085000e41290d95ce0c373a654b4a"
|
|||
dependencies = [
|
||||
"getrandom",
|
||||
"js-sys",
|
||||
"rand",
|
||||
"serde_core",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -5,5 +5,6 @@ edition = "2024"
|
|||
|
||||
[dependencies]
|
||||
bevy = "0.17.3"
|
||||
bevy_kira_audio = "0.24.0"
|
||||
derive_more = "2.1.1"
|
||||
rand = "0.9.2"
|
||||
|
|
|
|||
BIN
assets/sounds/king_dede_theme.ogg
Normal file
BIN
assets/sounds/king_dede_theme.ogg
Normal file
Binary file not shown.
BIN
assets/sounds/kirby-poyo.ogg
Normal file
BIN
assets/sounds/kirby-poyo.ogg
Normal file
Binary file not shown.
BIN
assets/sounds/kirby_hurt.ogg
Normal file
BIN
assets/sounds/kirby_hurt.ogg
Normal file
Binary file not shown.
BIN
assets/sounds/suction.ogg
Normal file
BIN
assets/sounds/suction.ogg
Normal file
Binary file not shown.
|
|
@ -3,8 +3,10 @@ use std::time::Duration;
|
|||
|
||||
use crate::core::game_state::DispawnOnGameOver;
|
||||
use crate::core::kirby::{Kirby, kirby_spawn};
|
||||
use crate::juice::sound::Poyoo;
|
||||
use crate::physics::sphere_collider::SphereCollider;
|
||||
use bevy::prelude::*;
|
||||
use bevy_kira_audio::{AudioChannel, AudioControl};
|
||||
|
||||
const ASSETS_NAME: [&str; 3] = ["speed_item.png", "shield_item.png", "kirby_item.png"];
|
||||
const COLLECTABLE_COLLIDER_RADIUS: f32 = 50.0;
|
||||
|
|
@ -94,11 +96,13 @@ fn kirby_spawn_timer(
|
|||
mut texture_atlas_layouts: ResMut<Assets<TextureAtlasLayout>>,
|
||||
query: Query<(&mut KirbySpawnHandler, Entity)>,
|
||||
time: Res<Time>,
|
||||
poyoo_chan: Res<AudioChannel<Poyoo>>,
|
||||
) {
|
||||
for (mut kirby_spawn_handler, kirby_spawn_entity) in query {
|
||||
kirby_spawn_handler.timer.tick(time.delta());
|
||||
if kirby_spawn_handler.timer.is_finished() {
|
||||
kirby_spawn(&mut commands, &asset_server, &mut texture_atlas_layouts, kirby_spawn_handler.position);
|
||||
poyoo_chan.play(asset_server.load("sounds/kirby-poyo.ogg"));
|
||||
commands.entity(kirby_spawn_entity).despawn();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
use crate::core::game_state::{GameStartupSet, DispawnOnGameOver};
|
||||
use crate::{
|
||||
core::game_state::{DispawnOnGameOver, GameStartupSet},
|
||||
juice::sound::Suction,
|
||||
};
|
||||
use bevy::prelude::*;
|
||||
use bevy_kira_audio::prelude::*;
|
||||
|
||||
const KIRBY_SCALE: f32 = 3.0;
|
||||
|
||||
|
|
@ -91,18 +95,22 @@ pub fn get_dir(keys: Res<ButtonInput<KeyCode>>) -> Vec2 {
|
|||
pub fn kirby_actions(
|
||||
keys: Res<ButtonInput<KeyCode>>,
|
||||
mut query: Query<(&mut PhysicsBody, &mut Kirby, &mut AnimationIndices, &mut Transform), With<Kirby>>,
|
||||
asset_server: Res<AssetServer>,
|
||||
suction_audio: Res<AudioChannel<Suction>>,
|
||||
) {
|
||||
let space_just_pressed = keys.just_pressed(KeyCode::Space);
|
||||
let space_just_released = keys.just_released(KeyCode::Space);
|
||||
let dir = get_dir(keys);
|
||||
for (mut body, mut kirby, mut anim_indices, mut transform) in &mut query {
|
||||
if space_just_released {
|
||||
kirby.is_sucking = false
|
||||
kirby.is_sucking = false;
|
||||
suction_audio.stop();
|
||||
};
|
||||
|
||||
if space_just_pressed {
|
||||
kirby.is_sucking = true;
|
||||
anim_indices.change(0, 2);
|
||||
suction_audio.play(asset_server.load("sounds/suction.ogg"));
|
||||
};
|
||||
|
||||
if kirby.is_sucking {
|
||||
|
|
|
|||
|
|
@ -83,6 +83,10 @@ fn get_bubble_waves() -> BubbleWaves {
|
|||
BubbleSplash::new(NORMAL_BUBBLE, TOP, 100.0, 100),
|
||||
BubbleSplash::new(RED_BUBBLE, BOTTOM, 10.0, 20),
|
||||
],
|
||||
vec![
|
||||
BubbleSplash::new(NORMAL_BUBBLE, RIGHT + TOP, 100.0, 200),
|
||||
BubbleSplash::new(RED_BUBBLE, RIGHT + TOP, 100.0, 100),
|
||||
],
|
||||
vec![
|
||||
BubbleSplash::new(NORMAL_BUBBLE, RIGHT - UP_DIR * 20.0, 100.0, 200),
|
||||
BubbleSplash::new(RED_BUBBLE, RIGHT + UP_DIR * 20.0, 100.0, 100),
|
||||
|
|
@ -104,6 +108,7 @@ fn get_bubble_waves() -> BubbleWaves {
|
|||
vec![(CollectableType::NewKirby, LEFT)],
|
||||
vec![(CollectableType::SpeedBoost, BOTTOM)],
|
||||
vec![(CollectableType::ShieldBoost, BOTTOM)],
|
||||
vec![(CollectableType::NewKirby, BOTTOM + LEFT)],
|
||||
vec![
|
||||
(CollectableType::ShieldBoost, TOP),
|
||||
(CollectableType::ShieldBoost, TOP + RIGHT_DIR * 40.0),
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
pub mod animation;
|
||||
pub mod camera;
|
||||
pub mod sound;
|
||||
pub mod ui;
|
||||
|
|
|
|||
32
src/juice/sound.rs
Normal file
32
src/juice/sound.rs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy_kira_audio::prelude::*;
|
||||
use std::path::Path;
|
||||
|
||||
use crate::core::game_state::{GameStartupSet, GameState};
|
||||
|
||||
fn restart_audio(asset_server: Res<AssetServer>, audio: Res<Audio>, background: Res<AudioChannel<Background>>) {
|
||||
audio.stop();
|
||||
background.stop();
|
||||
background.play(asset_server.load("sounds/king_dede_theme.ogg")).looped();
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct Background;
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct Suction;
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct Poyoo;
|
||||
|
||||
pub struct MySoundPlugin;
|
||||
|
||||
impl Plugin for MySoundPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_plugins(AudioPlugin)
|
||||
.add_audio_channel::<Background>()
|
||||
.add_audio_channel::<Suction>()
|
||||
.add_audio_channel::<Poyoo>()
|
||||
.add_systems(OnEnter(GameState::Starting), restart_audio.in_set(GameStartupSet));
|
||||
}
|
||||
}
|
||||
|
|
@ -23,6 +23,7 @@ use juice::camera::MyCameraPlugin;
|
|||
|
||||
use crate::core::game_state::GameEventsPlugin;
|
||||
use crate::core::wave::WavePlugin;
|
||||
use crate::juice::sound::MySoundPlugin;
|
||||
use crate::juice::ui::UIPlugin;
|
||||
|
||||
fn main() {
|
||||
|
|
@ -45,6 +46,7 @@ fn main() {
|
|||
.add_plugins(CollectablePlugin)
|
||||
.add_plugins(WavePlugin)
|
||||
.add_plugins(UIPlugin)
|
||||
.add_plugins(MySoundPlugin)
|
||||
.insert_resource(Time::<Fixed>::from_seconds(1.0 / 60.0))
|
||||
.insert_resource(MapBounds { min: -Vec2::ONE * MAP_WIDTH as f32, max: Vec2::ONE * MAP_WIDTH as f32 })
|
||||
.add_systems(Update, animate_sprite)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue