add background music

This commit is contained in:
Jim 2025-09-02 19:59:48 -04:00
parent c6d9a002b6
commit 86f2345667
Signed by: jim
GPG key ID: 3D7D94BA53088BF4
13 changed files with 210 additions and 8 deletions

View file

@ -8,6 +8,7 @@ bevy = { workspace = true }
bevy_egui = { workspace = true }
state = { path = "../state" }
combat = { path = "../combat" }
music = { path = "../music" }
[lints]
workspace = true

View file

@ -8,6 +8,7 @@ use bevy_egui::{
egui::{self, Align2, RichText},
};
use combat::Difficulty;
use music::BackgroundMusicPlayer;
use state::AppState;
pub struct UiMenuPlugin;
@ -22,6 +23,7 @@ impl Plugin for UiMenuPlugin {
difficulty_screen.run_if(in_state(MenuScreen::Difficulty)),
info_screen.run_if(in_state(MenuScreen::Info)),
settings_screen.run_if(in_state(MenuScreen::Settings)),
credits_screen.run_if(in_state(MenuScreen::Credits)),
),
)
.add_sub_state::<MenuScreen>();
@ -39,6 +41,7 @@ enum MenuScreen {
Info,
Difficulty,
Settings,
Credits,
}
fn setup_menu(mut commands: Commands) {
@ -96,6 +99,14 @@ fn main_screen(mut contexts: EguiContexts, mut next_screen: ResMut<NextState<Men
next_screen.set(MenuScreen::Settings);
}
});
ui.centered_and_justified(|ui| {
if ui
.button(RichText::new("CREDITS").size(VERY_LARGE_FONT_SIZE))
.clicked()
{
next_screen.set(MenuScreen::Credits);
}
});
});
}
@ -212,6 +223,7 @@ fn settings_screen(
mut contexts: EguiContexts,
mut next_screen: ResMut<NextState<MenuScreen>>,
mut global_volume: ResMut<GlobalVolume>,
mut music_query: Query<&mut AudioSink, With<BackgroundMusicPlayer>>,
mut volume: Local<f32>,
mut init: Local<bool>,
) {
@ -230,6 +242,77 @@ fn settings_screen(
ui.label(RichText::new("Volume").size(FONT_SIZE));
ui.add(egui::Slider::new(&mut *volume, 0.0..=100.));
global_volume.volume = Volume::Linear(*volume / 100.);
if let Ok(mut sink) = music_query.single_mut() {
sink.set_volume(Volume::Linear(*volume / 100.));
}
});
egui::Window::new("SettingsBack")
.resizable(false)
.collapsible(false)
.title_bar(false)
.anchor(Align2::LEFT_TOP, [0., 0.])
.show(ctx, |ui| {
if ui
.button(RichText::new("BACK").size(VERY_LARGE_FONT_SIZE))
.clicked()
{
next_screen.set(MenuScreen::Main);
}
});
}
fn credits_screen(mut contexts: EguiContexts, mut next_screen: ResMut<NextState<MenuScreen>>) {
let ctx = contexts.ctx_mut().unwrap();
egui::Window::new("SettingsScreen")
.resizable(false)
.collapsible(false)
.title_bar(false)
.anchor(Align2::CENTER_CENTER, [0., 0.])
.fixed_size([800., 100.])
.show(ctx, |ui| {
ui.heading("Created by Jim Moore");
ui.heading("Music (in game)");
ui.label(
RichText::new(
"\"Aquarium\" Kevin MacLeod (incompetech.com)
Licensed under Creative Commons: By Attribution 4.0 License
http://creativecommons.org/licenses/by/4.0/",
)
.size(FONT_SIZE),
);
ui.label(
RichText::new(
"\"Egmont Overture\" Kevin MacLeod (incompetech.com)
Licensed under Creative Commons: By Attribution 4.0 License
http://creativecommons.org/licenses/by/4.0/",
)
.size(FONT_SIZE),
);
ui.label(
RichText::new(
"\"Ghost Dance\" Kevin MacLeod (incompetech.com)
Licensed under Creative Commons: By Attribution 4.0 License
http://creativecommons.org/licenses/by/4.0/",
)
.size(FONT_SIZE),
);
ui.heading("Music (menu)");
ui.label(
RichText::new(
"\"Gymnopedie No. 3\" Kevin MacLeod (incompetech.com)
Licensed under Creative Commons: By Attribution 4.0 License
http://creativecommons.org/licenses/by/4.0/",
)
.size(FONT_SIZE),
);
ui.label(
RichText::new(
"\"A Very Brady Special\" Kevin MacLeod (incompetech.com)
Licensed under Creative Commons: By Attribution 4.0 License
http://creativecommons.org/licenses/by/4.0/",
)
.size(FONT_SIZE),
);
});
egui::Window::new("SettingsBack")
.resizable(false)