Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding audio effects for door and elevator (#226)
Browse files Browse the repository at this point in the history
porkbrain authored Jul 21, 2024
1 parent 63e2a21 commit 1349a2f
Showing 13 changed files with 375 additions and 16 deletions.
320 changes: 313 additions & 7 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ bevy-inspector-egui = { version = "0.25", default-features = false, features = [
] }
leafwing-input-manager = "0.14"
bevy_egui = "0.28"
bevy_kira_audio = "0.20"

scene_top_down = { path = "scenes/top_down" }
scene_meditation = { path = "scenes/meditation" }
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -27,18 +27,19 @@ We use some external dependencies.
It's paramount that we keep the bevy related dependencies to a minimum with the current Bevy release schedule.
With every extra dependency that also depends on Bevy it potentially takes longer to start upgrading.

- [`bevy_pixel_camera`][bevy_pixel_camera]
- [`bevy_pixel_camera`][bevy_pixel_camera] is used to scale the game to a pixel art resolution. This plugin seems to be no longer maintained and we will vendor it soon
- [`bevy_webp_anim`][bevy_webp_anim] is a crate we maintain so not a problem
- [`bevy-inspector-egui`][bevy-inspector-egui]
- [`leafwing-input-manager`][leafwing-input-manager] is maintained by a core Bevy contributor
- [`bevy_egui`][bevy_egui]
- [`bevy_kira_audio`][bevy_kira_audio] is used for audio. This decision was made based on some discord conversations that suggested it was better than the native Bevy audio plugin
- [`bevy_egui`][bevy_egui] and [`bevy-inspector-egui`][bevy-inspector-egui] are used for devtools

[bevy_egui]: https://github.com/mvlabat/bevy_egui
[bevy_kira_audio]: https://github.com/NiklasEi/bevy_kira_audio
[bevy_pixel_camera]: https://github.com/drakmaniso/bevy_pixel_camera
[bevy_webp_anim]: https://github.com/bausano/bevy-webp-anim
[bevy-inspector-egui]: https://github.com/jakobhellermann/bevy-inspector-egui
[leafwing-input-manager]: https://github.com/Leafwing-Studios/leafwing-input-manager
[original-bevy_magic_light]: https://github.com/zaycev/bevy-magic-light-2d
[bevy_egui]: https://github.com/mvlabat/bevy_egui

# Dev environment

5 changes: 5 additions & 0 deletions common/assets/src/paths.rs
Original file line number Diff line number Diff line change
@@ -123,3 +123,8 @@ pub mod ui {

pub const HEARTBEAT_ATLAS_SIZE: UVec2 = UVec2::splat(70);
}

pub mod audio {
pub const DOOR_OPEN: &str = "audio/door_open.oga";
pub const CALL_ELEVATOR: &str = "audio/call_elevator.oga";
}
File renamed without changes.
2 changes: 1 addition & 1 deletion main_game/assets/scenes/building1_player_floor.tscn
Original file line number Diff line number Diff line change
@@ -591,7 +591,7 @@ position = Vector2(132, -111)
[node name="InspectLabel" type="Node" parent="PlayerApartment/BackwallFurniture/BrewTea"]
metadata/zone = "Tea"
metadata/action = "BrewTea"
metadata/label = "Winnie Put the Kettle On"
metadata/label = "Winnie Put the Kettle On"

[node name="CandleLight" type="AnimatedSprite2D" parent="PlayerApartment/BackwallFurniture"]
position = Vector2(-29.5, -132)
1 change: 1 addition & 0 deletions main_game_lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ devtools = [
[dependencies]
bevy_egui = { workspace = true, optional = true }
bevy_grid_squared.workspace = true
bevy_kira_audio.workspace = true
bevy_pixel_camera.workspace = true
bevy_webp_anim.workspace = true
bevy-inspector-egui = { workspace = true, optional = true }
31 changes: 30 additions & 1 deletion main_game_lib/src/cutscene.rs
Original file line number Diff line number Diff line change
@@ -15,8 +15,12 @@ pub mod enter_dark_door;

use std::sync::OnceLock;

use bevy::{ecs::system::SystemId, prelude::*, render::view::RenderLayers};
use bevy::{
asset::AssetPath, ecs::system::SystemId, prelude::*,
render::view::RenderLayers,
};
use bevy_grid_squared::{GridDirection, Square};
use bevy_kira_audio::{Audio, AudioControl};
use common_ext::QueryExt;
use common_loading_screen::{LoadingScreenSettings, LoadingScreenState};
use common_store::GlobalStore;
@@ -238,6 +242,12 @@ pub enum CutsceneStep {
/// Undoes [`Self::ClaimManualMainCameraControl`] by inserting
/// [`ManualControl`] to the [`MainCamera`] entity.
ReleaseManualMainCameraControl,
/// Plays an audio file.
/// Immediately transitions to the next step.
StartPlayingAudio {
/// Relative to the asset folder
asset_path: AssetPath<'static>,
},
}

/// Marks a destination.
@@ -469,6 +479,7 @@ struct CutsceneSystems {
claim_manual_main_camera_control: SystemId,
release_manual_main_camera_control: SystemId,
begin_color_interpolation: SystemId,
start_playing_audio: SystemId,
}

impl CutsceneSystems {
@@ -503,6 +514,7 @@ impl CutsceneSystems {
.register_system(release_manual_main_camera_control),
begin_color_interpolation: w
.register_system(begin_color_interpolation),
start_playing_audio: w.register_system(start_playing_audio),
}
}
}
@@ -537,6 +549,7 @@ fn system_id(step: &CutsceneStep) -> SystemId {
ClaimManualMainCameraControl => s.claim_manual_main_camera_control,
BeginColorInterpolation { .. } => s.begin_color_interpolation,
ReleaseManualMainCameraControl => s.release_manual_main_camera_control,
StartPlayingAudio { .. } => s.start_playing_audio,
}
}

@@ -923,3 +936,19 @@ fn begin_color_interpolation(

cutscene.schedule_next_step_or_despawn(&mut cmd);
}

fn start_playing_audio(
mut cmd: Commands,
mut cutscene: ResMut<Cutscene>,
audio: Res<Audio>,
asset_server: Res<AssetServer>,
) {
let step = &cutscene.sequence[cutscene.sequence_index];
let CutsceneStep::StartPlayingAudio { asset_path } = &step else {
panic!("Expected StartPlayingAudio step, got {step}");
};

audio.play(asset_server.load(asset_path));

cutscene.schedule_next_step_or_despawn(&mut cmd);
}
4 changes: 4 additions & 0 deletions main_game_lib/src/cutscene/enter_an_elevator.rs
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
use std::{iter, str::FromStr};

use bevy_grid_squared::{GridDirection, Square};
use common_assets::audio::CALL_ELEVATOR;
use common_loading_screen::{LoadingScreenAtlas, LoadingScreenSettings};
use common_store::{DialogStore, GlobalStore};
use common_story::Character;
@@ -85,6 +86,9 @@ impl IntoCutscene for EnterAnElevator {
mode: TimerMode::Repeating,
},
Sleep(from_millis(1250)),
StartPlayingAudio {
asset_path: CALL_ELEVATOR.into(),
},
// jump into the elevator
BeginSimpleWalkTo {
with: player,
4 changes: 3 additions & 1 deletion main_game_lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ pub mod top_down;
pub mod vec2_ext;

use bevy::{app::AppExit, prelude::*};
use bevy_kira_audio::AudioPlugin;
use bevy_pixel_camera::PixelCameraPlugin;
pub use common_ext;

@@ -67,7 +68,8 @@ pub fn windowed_app() -> App {
}),
..default()
}),
);
)
.add_plugins(AudioPlugin);

info!("Initializing Don't Count The Sheep");

12 changes: 11 additions & 1 deletion main_game_lib/src/top_down/environmental_objects/door.rs
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
use bevy::prelude::*;
use bevy_grid_squared::Square;
use bevy_kira_audio::{Audio, AudioControl};
use common_assets::audio::DOOR_OPEN;
use itertools::Itertools;
use smallvec::SmallVec;

@@ -74,6 +76,8 @@ pub enum DoorOpenCriteria {
/// Run this after the [`crate::top_down::actor::emit_movement_events`] system
/// and only if there are events.
pub fn toggle(
asset_server: Res<AssetServer>,
audio: Res<Audio>,
mut tilemap: ResMut<TileMap>,
mut events: EventReader<ActorMovementEvent>,

@@ -84,6 +88,8 @@ pub fn toggle(
for (mut door, mut sprite) in door.iter_mut() {
for event in &events {
apply_event_to_door_and_map(
&asset_server,
&audio,
&mut tilemap,
&mut door,
&mut sprite,
@@ -99,7 +105,9 @@ pub fn toggle(
/// Optionally, the door can have an obstacle that's inserted into the map when
/// the door is closed.
fn apply_event_to_door_and_map(
tilemap: &mut ResMut<TileMap>,
asset_server: &AssetServer,
audio: &Audio,
tilemap: &mut TileMap,
door: &mut Door,
sprite: &mut Mut<'_, TextureAtlas>,
event: &ActorMovementEvent,
@@ -127,6 +135,8 @@ fn apply_event_to_door_and_map(

trace!("Open door");

audio.play(asset_server.load(DOOR_OPEN));

door.state = DoorState::Open;
sprite.index = 1;

2 changes: 1 addition & 1 deletion main_game_lib/src/top_down/inspect_and_interact.rs
Original file line number Diff line number Diff line change
@@ -486,7 +486,7 @@ fn spawn_label_bg_and_text(
// then using the logical size, and the impression doesn't
// matter for such a short text
let bg_box_width =
font_size + font_size / 7.0 * text_to_display.len() as f32;
font_size + font_size / 6.0 * text_to_display.len() as f32;
let bg = cmd
.spawn(InspectLabelBg)
.insert(Name::new("InspectLabelBg"))

0 comments on commit 1349a2f

Please sign in to comment.