Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename things #272

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/asset_tracking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use bevy::prelude::*;

pub(super) fn plugin(app: &mut App) {
app.init_resource::<ResourceHandles>()
.add_systems(PreUpdate, load_resource_assets);
app.init_resource::<ResourceHandles>();
app.add_systems(PreUpdate, load_resource_assets);
}

pub trait LoadResource {
Expand Down
4 changes: 2 additions & 2 deletions src/demo/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(super) fn plugin(app: &mut App) {
(
update_animation_movement,
update_animation_atlas,
trigger_step_sfx,
trigger_step_sound_effect,
)
.chain()
.run_if(resource_exists::<PlayerAssets>)
Expand Down Expand Up @@ -68,7 +68,7 @@ fn update_animation_atlas(mut query: Query<(&PlayerAnimation, &mut TextureAtlas)

/// If the player is moving, play a step sound effect synchronized with the
/// animation.
fn trigger_step_sfx(
fn trigger_step_sound_effect(
mut commands: Commands,
player_assets: Res<PlayerAssets>,
mut step_query: Query<&PlayerAnimation>,
Expand Down
10 changes: 5 additions & 5 deletions src/demo/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn spawn_player(
},
ScreenWrap,
player_animation,
StateScoped(Screen::Playing),
StateScoped(Screen::Gameplay),
));
}

Expand Down Expand Up @@ -125,10 +125,10 @@ pub struct PlayerAssets {

impl PlayerAssets {
pub const PATH_DUCKY: &'static str = "images/ducky.png";
pub const PATH_STEP_1: &'static str = "audio/sfx/step1.ogg";
pub const PATH_STEP_2: &'static str = "audio/sfx/step2.ogg";
pub const PATH_STEP_3: &'static str = "audio/sfx/step3.ogg";
pub const PATH_STEP_4: &'static str = "audio/sfx/step4.ogg";
pub const PATH_STEP_1: &'static str = "audio/sound_effects/step1.ogg";
pub const PATH_STEP_2: &'static str = "audio/sound_effects/step2.ogg";
pub const PATH_STEP_3: &'static str = "audio/sound_effects/step3.ogg";
pub const PATH_STEP_4: &'static str = "audio/sound_effects/step4.ogg";
}

impl FromWorld for PlayerAssets {
Expand Down
56 changes: 30 additions & 26 deletions src/screens/credits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,14 @@ use bevy::prelude::*;
use crate::{asset_tracking::LoadResource, audio::Music, screens::Screen, theme::prelude::*};

pub(super) fn plugin(app: &mut App) {
app.load_resource::<CreditsMusic>();
app.add_systems(OnEnter(Screen::Credits), show_credits_screen);
app.add_systems(OnExit(Screen::Credits), stop_bgm);
}

#[derive(Resource, Asset, Reflect, Clone)]
pub struct CreditsMusic {
#[dependency]
music: Handle<AudioSource>,
entity: Option<Entity>,
}
app.add_systems(OnEnter(Screen::Credits), spawn_credits_screen);

impl FromWorld for CreditsMusic {
fn from_world(world: &mut World) -> Self {
let assets = world.resource::<AssetServer>();
Self {
music: assets.load("audio/bgm/Monkeys Spinning Monkeys.ogg"),
entity: None,
}
}
app.load_resource::<CreditsMusic>();
app.add_systems(OnEnter(Screen::Credits), play_credits_music);
app.add_systems(OnExit(Screen::Credits), stop_music);
}

fn show_credits_screen(mut commands: Commands, mut music: ResMut<CreditsMusic>) {
fn spawn_credits_screen(mut commands: Commands) {
commands
.ui_root()
.insert(StateScoped(Screen::Credits))
Expand All @@ -42,9 +27,32 @@ fn show_credits_screen(mut commands: Commands, mut music: ResMut<CreditsMusic>)
children.label("Button SFX - CC0 by Jaszunio15");
children.label("Music - CC BY 3.0 by Kevin MacLeod");

children.button("Back").observe(enter_title);
children.button("Back").observe(enter_title_screen);
});
}

fn enter_title_screen(_trigger: Trigger<OnPress>, mut next_screen: ResMut<NextState<Screen>>) {
next_screen.set(Screen::Title);
}

#[derive(Resource, Asset, Reflect, Clone)]
pub struct CreditsMusic {
#[dependency]
music: Handle<AudioSource>,
entity: Option<Entity>,
}

impl FromWorld for CreditsMusic {
fn from_world(world: &mut World) -> Self {
let assets = world.resource::<AssetServer>();
Self {
music: assets.load("audio/music/Monkeys Spinning Monkeys.ogg"),
entity: None,
}
}
}

fn play_credits_music(mut commands: Commands, mut music: ResMut<CreditsMusic>) {
music.entity = Some(
commands
.spawn((
Expand All @@ -58,12 +66,8 @@ fn show_credits_screen(mut commands: Commands, mut music: ResMut<CreditsMusic>)
);
}

fn stop_bgm(mut commands: Commands, mut music: ResMut<CreditsMusic>) {
fn stop_music(mut commands: Commands, mut music: ResMut<CreditsMusic>) {
if let Some(entity) = music.entity.take() {
commands.entity(entity).despawn_recursive();
}
}

fn enter_title(_trigger: Trigger<OnPress>, mut next_screen: ResMut<NextState<Screen>>) {
next_screen.set(Screen::Title);
}
19 changes: 12 additions & 7 deletions src/screens/playing.rs → src/screens/gameplay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ use crate::{
};

pub(super) fn plugin(app: &mut App) {
app.add_systems(OnEnter(Screen::Gameplay), spawn_level);

app.load_resource::<GameplayMusic>();
app.add_systems(OnEnter(Screen::Playing), spawn_level);
app.add_systems(OnExit(Screen::Playing), stop_bgm);
app.add_systems(OnEnter(Screen::Gameplay), play_gameplay_music);
app.add_systems(OnExit(Screen::Gameplay), stop_music);

app.add_systems(
Update,
return_to_title_screen
.run_if(in_state(Screen::Playing).and_then(input_just_pressed(KeyCode::Escape))),
.run_if(in_state(Screen::Gameplay).and_then(input_just_pressed(KeyCode::Escape))),
);
}

fn spawn_level(mut commands: Commands) {
commands.add(spawn_level_command);
}

#[derive(Resource, Asset, Reflect, Clone)]
pub struct GameplayMusic {
#[dependency]
Expand All @@ -30,14 +36,13 @@ impl FromWorld for GameplayMusic {
fn from_world(world: &mut World) -> Self {
let assets = world.resource::<AssetServer>();
Self {
handle: assets.load("audio/bgm/Fluffing A Duck.ogg"),
handle: assets.load("audio/music/Fluffing A Duck.ogg"),
entity: None,
}
}
}

fn spawn_level(mut commands: Commands, mut music: ResMut<GameplayMusic>) {
commands.add(spawn_level_command);
fn play_gameplay_music(mut commands: Commands, mut music: ResMut<GameplayMusic>) {
music.entity = Some(
commands
.spawn((
Expand All @@ -51,7 +56,7 @@ fn spawn_level(mut commands: Commands, mut music: ResMut<GameplayMusic>) {
);
}

fn stop_bgm(mut commands: Commands, mut music: ResMut<GameplayMusic>) {
fn stop_music(mut commands: Commands, mut music: ResMut<GameplayMusic>) {
if let Some(entity) = music.entity.take() {
commands.entity(entity).despawn_recursive();
}
Expand Down
17 changes: 9 additions & 8 deletions src/screens/loading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ use bevy::prelude::*;

use crate::{
demo::player::PlayerAssets,
screens::{credits::CreditsMusic, playing::GameplayMusic, Screen},
screens::{credits::CreditsMusic, gameplay::GameplayMusic, Screen},
theme::{interaction::InteractionAssets, prelude::*},
};

pub(super) fn plugin(app: &mut App) {
app.add_systems(OnEnter(Screen::Loading), show_loading_screen);
app.add_systems(OnEnter(Screen::Loading), spawn_loading_screen);

app.add_systems(
Update,
continue_to_title.run_if(in_state(Screen::Loading).and_then(all_assets_loaded)),
continue_to_title_screen.run_if(in_state(Screen::Loading).and_then(all_assets_loaded)),
);
}

fn show_loading_screen(mut commands: Commands) {
fn spawn_loading_screen(mut commands: Commands) {
commands
.ui_root()
.insert(StateScoped(Screen::Loading))
Expand All @@ -29,6 +30,10 @@ fn show_loading_screen(mut commands: Commands) {
});
}

fn continue_to_title_screen(mut next_screen: ResMut<NextState<Screen>>) {
next_screen.set(Screen::Title);
}

fn all_assets_loaded(
player_assets: Option<Res<PlayerAssets>>,
interaction_assets: Option<Res<InteractionAssets>>,
Expand All @@ -40,7 +45,3 @@ fn all_assets_loaded(
&& credits_music.is_some()
&& gameplay_music.is_some()
}

fn continue_to_title(mut next_screen: ResMut<NextState<Screen>>) {
next_screen.set(Screen::Title);
}
12 changes: 6 additions & 6 deletions src/screens/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! The game's main screen states and transitions between them.

pub mod credits;
mod credits;
mod gameplay;
mod loading;
pub mod playing;
mod splash;
mod title;

Expand All @@ -13,11 +13,11 @@ pub(super) fn plugin(app: &mut App) {
app.enable_state_scoped_entities::<Screen>();

app.add_plugins((
splash::plugin,
credits::plugin,
gameplay::plugin,
loading::plugin,
splash::plugin,
title::plugin,
credits::plugin,
playing::plugin,
));
}

Expand All @@ -29,5 +29,5 @@ pub enum Screen {
Loading,
Title,
Credits,
Playing,
Gameplay,
}
14 changes: 7 additions & 7 deletions src/screens/splash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{screens::Screen, theme::prelude::*, AppSet};
pub(super) fn plugin(app: &mut App) {
// Spawn splash screen.
app.insert_resource(ClearColor(SPLASH_BACKGROUND_COLOR));
app.add_systems(OnEnter(Screen::Splash), spawn_splash);
app.add_systems(OnEnter(Screen::Splash), spawn_splash_screen);

// Animate splash screen.
app.add_systems(
Expand Down Expand Up @@ -39,7 +39,7 @@ pub(super) fn plugin(app: &mut App) {
// Exit the splash screen early if the player hits escape.
app.add_systems(
Update,
exit_splash_screen
continue_to_loading_screen
.run_if(input_just_pressed(KeyCode::Escape).and_then(in_state(Screen::Splash))),
);
}
Expand All @@ -48,11 +48,7 @@ const SPLASH_BACKGROUND_COLOR: Color = Color::srgb(0.157, 0.157, 0.157);
const SPLASH_DURATION_SECS: f32 = 1.8;
const SPLASH_FADE_DURATION_SECS: f32 = 0.6;

fn exit_splash_screen(mut next_screen: ResMut<NextState<Screen>>) {
next_screen.set(Screen::Loading);
}

fn spawn_splash(mut commands: Commands, asset_server: Res<AssetServer>) {
fn spawn_splash_screen(mut commands: Commands, asset_server: Res<AssetServer>) {
commands
.ui_root()
.insert((
Expand Down Expand Up @@ -151,3 +147,7 @@ fn check_splash_timer(timer: ResMut<SplashTimer>, mut next_screen: ResMut<NextSt
next_screen.set(Screen::Loading);
}
}

fn continue_to_loading_screen(mut next_screen: ResMut<NextState<Screen>>) {
next_screen.set(Screen::Loading);
}
2 changes: 1 addition & 1 deletion src/screens/title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn show_title_screen(mut commands: Commands) {
}

fn enter_playing(_trigger: Trigger<OnPress>, mut next_screen: ResMut<NextState<Screen>>) {
next_screen.set(Screen::Playing);
next_screen.set(Screen::Gameplay);
}

fn enter_credits(_trigger: Trigger<OnPress>, mut next_screen: ResMut<NextState<Screen>>) {
Expand Down
8 changes: 4 additions & 4 deletions src/theme/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub(super) fn plugin(app: &mut App) {
(
trigger_on_press,
apply_interaction_palette,
trigger_interaction_sfx,
trigger_interaction_sound_effect,
)
.run_if(resource_exists::<InteractionAssets>),
);
Expand Down Expand Up @@ -68,8 +68,8 @@ pub struct InteractionAssets {
}

impl InteractionAssets {
pub const PATH_BUTTON_HOVER: &'static str = "audio/sfx/button_hover.ogg";
pub const PATH_BUTTON_PRESS: &'static str = "audio/sfx/button_press.ogg";
pub const PATH_BUTTON_HOVER: &'static str = "audio/sound_effects/button_hover.ogg";
pub const PATH_BUTTON_PRESS: &'static str = "audio/sound_effects/button_press.ogg";
}

impl FromWorld for InteractionAssets {
Expand All @@ -82,7 +82,7 @@ impl FromWorld for InteractionAssets {
}
}

fn trigger_interaction_sfx(
fn trigger_interaction_sound_effect(
interaction_query: Query<&Interaction, Changed<Interaction>>,
interaction_assets: Res<InteractionAssets>,
mut commands: Commands,
Expand Down