Skip to content

Commit

Permalink
Add intro screen
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Jul 28, 2024
1 parent a151b2f commit f484be9
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/game/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl EntityCommand for Stats {
.with_children(|children| {
for (i, text) in stats.into_iter().enumerate() {
children.spawn((
Name::new("StatsSpan"),
Name::new(format!("StatsSpan{}", i)),
TextBundle::from_sections(parse_rich(&text)).with_style(Style {
justify_self: if i % 2 == 0 {
JustifySelf::End
Expand Down
3 changes: 3 additions & 0 deletions src/screen.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod intro;
mod loading;
pub mod playing;
mod splash;
Expand All @@ -20,6 +21,7 @@ pub fn plugin(app: &mut App) {
app.add_plugins((
splash::plugin,
title::plugin,
intro::plugin,
loading::plugin,
playing::plugin,
));
Expand All @@ -32,6 +34,7 @@ pub enum Screen {
#[default]
Splash,
Title,
Intro,
Loading,
Playing,
}
Expand Down
151 changes: 151 additions & 0 deletions src/screen/intro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
use bevy::prelude::*;
use bevy_asset_loader::prelude::*;
use bevy_mod_picking::prelude::*;
use iyes_progress::prelude::*;
use pyri_state::prelude::*;

use crate::game::actor::health::HealthConfig;
use crate::game::actor::level::LevelConfig;
use crate::game::actor::ActorConfig;
use crate::game::audio::AudioConfig;
use crate::game::card::CardConfig;
use crate::game::combat::projectile::ProjectileConfig;
use crate::game::wave::WaveConfig;
use crate::screen::fade_in;
use crate::screen::fade_out;
use crate::screen::playing::PlayingAssets;
use crate::screen::Screen;
use crate::ui::prelude::*;
use crate::util::prelude::*;

pub(super) fn plugin(app: &mut App) {
app.add_loading_state(
LoadingState::new(Screen::Intro.bevy()).load_collection::<PlayingAssets>(),
);
app.add_plugins(ProgressPlugin::new(Screen::Intro.bevy()));
app.add_systems(StateFlush, Screen::Intro.on_enter(enter_intro));
app.add_systems(
Update,
// TODO: This is kinda silly. Find a better way later.
Screen::Intro.on_update((
ActorConfig::progress.track_progress(),
CardConfig::progress.track_progress(),
HealthConfig::progress.track_progress(),
LevelConfig::progress.track_progress(),
AudioConfig::progress.track_progress(),
ProjectileConfig::progress.track_progress(),
WaveConfig::progress.track_progress(),
)),
);
}

const HEADER: &str = "How to play:";

fn enter_intro(mut commands: Commands, ui_root: Res<UiRoot>) {
commands.spawn_with(fade_in);
commands.spawn_with(intro_screen).set_parent(ui_root.body);
}

fn intro_screen(mut entity: EntityWorldMut) {
entity
.add(Style::COLUMN_MID.div())
.insert(Name::new("IntroScreen"))
.with_children(|children| {
children.spawn_with(header);
children.spawn_with(body);
children.spawn_with(button_container);
});
}

fn header(mut entity: EntityWorldMut) {
entity.insert((
Name::new("Header"),
TextBundle::from_section(
HEADER,
TextStyle {
font: BOLD_FONT_HANDLE,
..default()
},
)
.with_style(Style {
margin: UiRect::vertical(Vw(5.0)),
..default()
}),
DynamicFontSize::new(Vw(5.0)).with_step(8.0),
ThemeColorForText(vec![ThemeColor::BodyText]),
));
}

fn body(mut entity: EntityWorldMut) {
entity
.insert((
Name::new("Body"),
NodeBundle {
style: Style {
flex_direction: FlexDirection::Column,
align_items: AlignItems::Center,
row_gap: Vw(1.4),
..default()
},
..default()
},
))
.with_children(|children| {
for (i, text) in [
"Cards are played to the rhythm,",
"use your mouse to aim.",
"Show off your moves to impress 'em,",
"reach [b]Level 10[r] for fame!",
]
.into_iter()
.enumerate()
{
children.spawn((
Name::new(format!("Span{}", i)),
TextBundle::from_sections(parse_rich(text)),
DynamicFontSize::new(Vw(3.5)).with_step(8.0),
ThemeColorForText(vec![
ThemeColor::BodyText,
ThemeColor::Indicator,
ThemeColor::BodyText,
]),
));
}
});
}

fn button_container(mut entity: EntityWorldMut) {
entity
.insert((
Name::new("ButtonContainer"),
NodeBundle {
style: Style {
width: Percent(100.0),
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
margin: UiRect::vertical(VMin(9.0)),
row_gap: Vw(2.5),
..default()
},
..default()
},
))
.with_children(|children| {
children.spawn_with(play_button);
});
}

fn play_button(mut entity: EntityWorldMut) {
entity
.add(widget::menu_button("Let's dance!"))
.insert(On::<Pointer<Click>>::run(
|mut commands: Commands, progress: Res<ProgressCounter>| {
let Progress { done, total } = progress.progress_complete();
commands.spawn_with(fade_out(if done >= total {
Screen::Playing
} else {
Screen::Loading
}));
},
));
}
5 changes: 0 additions & 5 deletions src/screen/splash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ use bevy::core::FrameCount;
use bevy::prelude::*;
use bevy::render::texture::ImageLoaderSettings;
use bevy::render::texture::ImageSampler;
use bevy_asset_loader::prelude::*;
use iyes_progress::prelude::*;
use pyri_state::prelude::*;

use crate::screen::fade_in;
use crate::screen::fade_out;
use crate::screen::title::TitleScreenAssets;
use crate::screen::Screen;
use crate::screen::FADE_IN_SECS;
use crate::ui::prelude::*;
Expand All @@ -19,9 +17,6 @@ use crate::util::time::wait;
pub(super) fn plugin(app: &mut App) {
embedded_asset!(app, "splash/splash.png");

app.add_loading_state(
LoadingState::new(Screen::Splash.bevy()).load_collection::<TitleScreenAssets>(),
);
app.add_plugins(ProgressPlugin::new(Screen::Splash.bevy()));
app.add_systems(StateFlush, Screen::Splash.on_enter(enter_splash));
app.add_systems(
Expand Down
65 changes: 9 additions & 56 deletions src/screen/title.rs
Original file line number Diff line number Diff line change
@@ -1,57 +1,15 @@
use bevy::prelude::*;
use bevy_asset_loader::prelude::*;
use bevy_mod_picking::prelude::*;
use iyes_progress::prelude::*;
use pyri_state::prelude::*;

use crate::game::actor::health::HealthConfig;
use crate::game::actor::level::LevelConfig;
use crate::game::actor::ActorConfig;
use crate::game::audio::AudioConfig;
use crate::game::card::CardConfig;
use crate::game::combat::projectile::ProjectileConfig;
use crate::game::wave::WaveConfig;
use crate::screen::fade_in;
use crate::screen::fade_out;
use crate::screen::playing::PlayingAssets;
use crate::screen::Screen;
use crate::ui::prelude::*;
use crate::util::prelude::*;

pub(super) fn plugin(app: &mut App) {
app.add_loading_state(
LoadingState::new(Screen::Title.bevy()).load_collection::<PlayingAssets>(),
);
app.add_plugins(ProgressPlugin::new(Screen::Title.bevy()));
app.add_systems(StateFlush, Screen::Title.on_enter(enter_title));
app.add_systems(
Update,
// TODO: This is kinda silly. Find a better way later.
Screen::Title.on_update((
ActorConfig::progress.track_progress(),
CardConfig::progress.track_progress(),
HealthConfig::progress.track_progress(),
LevelConfig::progress.track_progress(),
AudioConfig::progress.track_progress(),
ProjectileConfig::progress.track_progress(),
WaveConfig::progress.track_progress(),
)),
);

app.configure::<TitleScreenAssets>();
}

const TITLE: &str = "Blobo Party!";

#[derive(AssetCollection, Resource, Reflect, Default)]
#[reflect(Resource)]
pub struct TitleScreenAssets {}

impl Configure for TitleScreenAssets {
fn configure(app: &mut App) {
app.register_type::<Self>();
app.init_collection::<Self>();
}
}

fn enter_title(mut commands: Commands, ui_root: Res<UiRoot>) {
Expand All @@ -64,16 +22,18 @@ fn title_screen(mut entity: EntityWorldMut) {
.add(Style::COLUMN_MID.div())
.insert(Name::new("TitleScreen"))
.with_children(|children| {
children.spawn_with(title_text);
children.spawn_with(header);
children.spawn_with(button_container);
});
}

fn title_text(mut entity: EntityWorldMut) {
const HEADER: &str = "Blobo Party!";

fn header(mut entity: EntityWorldMut) {
entity.insert((
Name::new("TitleText"),
Name::new("Header"),
TextBundle::from_section(
TITLE,
HEADER,
TextStyle {
font: BOLD_FONT_HANDLE,
..default()
Expand Down Expand Up @@ -113,16 +73,9 @@ fn button_container(mut entity: EntityWorldMut) {
fn play_button(mut entity: EntityWorldMut) {
entity
.add(widget::menu_button("Play"))
.insert(On::<Pointer<Click>>::run(
|mut commands: Commands, progress: Res<ProgressCounter>| {
let Progress { done, total } = progress.progress_complete();
commands.spawn_with(fade_out(if done >= total {
Screen::Playing
} else {
Screen::Loading
}));
},
));
.insert(On::<Pointer<Click>>::run(|mut commands: Commands| {
commands.spawn_with(fade_out(Screen::Intro));
}));
}

fn quit_button(mut entity: EntityWorldMut) {
Expand Down

0 comments on commit f484be9

Please sign in to comment.