Skip to content

Commit

Permalink
button sounds
Browse files Browse the repository at this point in the history
removing random println

button clicking sounds update

cargo fmt & cargo clippy

cargo fmt

new audio at start game button
  • Loading branch information
DRuppFv committed Sep 2, 2022
1 parent 918b829 commit 9ed44ec
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 1 deletion.
Binary file added assets/ui/down_button_1.ogg
Binary file not shown.
Binary file added assets/ui/down_button_2.ogg
Binary file not shown.
Binary file added assets/ui/down_button_3.ogg
Binary file not shown.
Binary file added assets/ui/down_play_button.ogg
Binary file not shown.
Binary file added assets/ui/focused_button_1.ogg
Binary file not shown.
Binary file added assets/ui/focused_button_2.ogg
Binary file not shown.
Binary file added assets/ui/focused_button_3.ogg
Binary file not shown.
21 changes: 21 additions & 0 deletions src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Also for cleanness (named channels have evident function), we don't use the default channel.

use bevy::{prelude::*, utils::HashMap};
use bevy_egui::{egui::output::OutputEvent, EguiContext};
use bevy_kira_audio::{AudioApp, AudioChannel, AudioSource};
use iyes_loopless::prelude::*;

Expand Down Expand Up @@ -92,6 +93,26 @@ pub fn animation_audio_playback(
}
}

/// Plays main menu sounds
pub fn main_menu_sounds(
mut context: ResMut<EguiContext>,
effects_channel: Res<AudioChannel<EffectsChannel>>,
asset_server: Res<AssetServer>,
) {
for event in &context.ctx_mut().output().events {
println!("{:?}", event);
if let OutputEvent::Clicked(info) = event {
if info.label.as_ref().unwrap() == "Start Game" {
//Play down_play_button
effects_channel.play(asset_server.load("ui/down_play_button.ogg"));
} else {
//Play one of the down button audios, except down_play_button
effects_channel.play(asset_server.load("ui/down_button_1.ogg"));
}
}
}
}

pub fn play_menu_music(game_meta: Res<GameMeta>, music_channel: Res<AudioChannel<MusicChannel>>) {
// This is a workaround for a Bevy Kira bug where stopping a sound immediately after
// playing it doesn't work. We run into this issue when the menu starts and immediately
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ fn main() {
asset_server_settings.asset_folder = asset_dir.clone();
}
app.insert_resource(asset_server_settings);

// Add default plugins
#[cfg(feature = "schedule_graph")]
app.add_plugins_with(DefaultPlugins, |plugins| {
Expand Down Expand Up @@ -132,6 +131,10 @@ fn main() {
.run_in_state(GameState::InGame)
.with_system(game_over_on_players_death)
.into(),
)
.add_system_to_stage(
CoreStage::PostUpdate,
main_menu_sounds.before(bevy_egui::EguiSystem::ProcessOutput),
);

// Register reflect types that don't come from plugins
Expand Down

0 comments on commit 9ed44ec

Please sign in to comment.