Skip to content

Commit

Permalink
Loading to Title transition
Browse files Browse the repository at this point in the history
  • Loading branch information
bas-ie committed Dec 20, 2024
1 parent 5e610cc commit 845d992
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/assets.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use bevy::prelude::*;
use bevy_asset_loader::prelude::*;

use crate::screens::Screen;

pub fn plugin(app: &mut App) {
app.add_loading_state(LoadingState::new(Screen::Loading).continue_to_state(Screen::Title));
}

#[derive(AssetCollection, Resource)]
pub struct Textures {}
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod assets;
#[cfg(feature = "dev")]
mod dev_tools;
mod screens;
Expand Down Expand Up @@ -47,10 +48,8 @@ impl Plugin for GamePlugin {
}),
);

// Add other plugins.
app.add_plugins((screens::plugin,));
app.add_plugins((assets::plugin, screens::plugin));

// Enable dev tools for dev builds.
#[cfg(feature = "dev")]
app.add_plugins(dev_tools::plugin);
}
Expand Down
20 changes: 19 additions & 1 deletion src/screens.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
mod loading;
mod title;

use bevy::prelude::*;

pub fn plugin(mut app: &mut App) {}
pub fn plugin(app: &mut App) {
app.init_state::<Screen>();
app.enable_state_scoped_entities::<Screen>();

app.add_plugins((loading::plugin, title::plugin));
}

#[derive(States, Debug, Hash, PartialEq, Eq, Clone, Default)]
pub enum Screen {
#[default]
Loading,
// Over,
// Playing,
// Splash,
Title,
}
3 changes: 3 additions & 0 deletions src/screens/loading.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use bevy::prelude::*;

pub fn plugin(app: &mut App) {}
40 changes: 40 additions & 0 deletions src/screens/title.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use bevy::prelude::*;

use crate::screens::Screen;

pub(super) fn plugin(app: &mut App) {
app.add_systems(OnEnter(Screen::Title), spawn_title_screen);
}

fn spawn_title_screen(mut commands: Commands) {
commands
.spawn((StateScoped(Screen::Title), Name::new("Title"), Node {
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
height: Val::Percent(100.),
justify_content: JustifyContent::Start,
justify_self: JustifySelf::Center,
padding: UiRect::all(Val::Px(10.)),
width: Val::Percent(100.),
..default()
}))
.with_children(|p| {
p.spawn((Text::new("All The Way Home"), TextFont {
font_size: 30.,
..default()
}));
});
}

// fn enter_gameplay_screen(_trigger: Trigger<OnPress>, mut next_screen: ResMut<NextState<Screen>>) {
// next_screen.set(Screen::Playing);
// }
//
// fn enter_credits_screen(_trigger: Trigger<OnPress>, mut next_screen: ResMut<NextState<Screen>>) {
// next_screen.set(Screen::Credits);
// }
//
// #[cfg(not(target_family = "wasm"))]
// fn exit_app(_trigger: Trigger<OnPress>, mut app_exit: EventWriter<AppExit>) {
// app_exit.send(AppExit::Success);
// }

0 comments on commit 845d992

Please sign in to comment.