start music & sound
This commit is contained in:
parent
d168e48759
commit
061e311cf6
12 changed files with 215 additions and 6 deletions
|
|
@ -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