Skip to content

Commit

Permalink
Merge pull request #14 from SecretPocketCat/tutorial
Browse files Browse the repository at this point in the history
Tutorial
  • Loading branch information
SecretPocketCat authored Apr 10, 2023
2 parents 88f1d78 + 9284fb5 commit fcaea74
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 7 deletions.
64 changes: 60 additions & 4 deletions assets/sprites.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/controls_arrows.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/textures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ pub struct TextureAssets {

#[asset(path = "textures/button.png")]
pub button: Handle<Image>,

#[asset(path = "textures/controls_arrows.png")]
pub controls_arrows: Handle<Image>,
}
2 changes: 0 additions & 2 deletions src/state/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use bevy::{app::AppExit, prelude::*};
pub enum AppState {
#[default]
Loading,
SplashFade,
Splash,
// yes, this is hacky, but the jam end is nigh
Menu,
Game,
GameOver,
Expand Down
6 changes: 5 additions & 1 deletion src/ui/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ use super::UiDisabled;

pub(super) fn button_plugin(app: &mut App) {
app.init_resource::<ButtonColors>()
.add_system(spawn_ui_btn.run_if(resource_exists::<FontAssets>()))
.add_system(
spawn_ui_btn.run_if(
resource_exists::<FontAssets>().and_then(resource_exists::<TextureAssets>()),
),
)
.add_system(on_ui_btn_interaction);
}

Expand Down
2 changes: 2 additions & 0 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod game_over;
mod menu;
mod pause;
mod splash;
mod tutorial;

pub fn ui_plugin(app: &mut App) {
app.fn_plugin(button::button_plugin)
Expand All @@ -24,6 +25,7 @@ pub fn ui_plugin(app: &mut App) {
resource_exists::<RootUiNode>().and_then(resource_exists_and_changed::<AppSize>()),
))
.add_system(menu::setup_ui.in_schedule(OnEnter(AppState::Menu)))
.add_system(tutorial::setup_ui.in_schedule(OnEnter(AppState::Tutorial)))
.add_system(game_over::setup_ui.in_schedule(OnEnter(AppState::GameOver)))
.add_system(pause::setup_ui.in_schedule(OnEnter(GameState::Paused)))
.add_system(teardown_ui.in_schedule(OnExit(GameState::Paused)))
Expand Down
102 changes: 102 additions & 0 deletions src/ui/tutorial.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
use crate::{
assets::{fonts::FontAssets, textures::TextureAssets},
palette::{COL_BG, COL_TEXT},
state::AppState,
GAME_NAME,
};
use bevy::{prelude::*, text::BreakLineOn};

use super::{
button::{UiButton, UiButtonAction},
RootUiNode, UiDisabled,
};

pub(super) fn setup_ui(
mut cmd: Commands,
root: Res<RootUiNode>,
font_assets: Res<FontAssets>,
tex: Res<TextureAssets>,
) {
cmd.entity(root.0).with_children(|parent| {
for txt in [
"Welcome to the depths.",
"Your goal is to reach as deep as possible.",
"Move with the arrow keys or WASD or use a controller.",
] {
spawn_text(parent, &font_assets, txt);
}

parent.spawn(ImageBundle {
image: UiImage::new(tex.controls_arrows.clone()),
transform: Transform::from_scale(Vec2::splat(0.6).extend(1.)),
..default()
});

for txt in [
"Echolocate with space to explore your surroundings,",
"but beware of foes that might be lurking in the dark.",
] {
spawn_text(parent, &font_assets, txt);
}

parent
.spawn(ImageBundle {
image: UiImage::new(tex.button.clone()),
style: Style {
padding: UiRect {
top: Val::Px(10.),
bottom: Val::Px(10.),
left: Val::Px(30.),
right: Val::Px(30.),
},
margin: UiRect {
top: Val::Px(20.),
bottom: Val::Px(35.),
..default()
},
..default()
},
..Default::default()
})
.with_children(|parent| {
parent.spawn(TextBundle::from_section(
"space",
TextStyle {
font: font_assets.menu.clone(),
font_size: 60.,
color: COL_BG,
},
));
});

for txt in ["Find the portal to reach the next level and delve deeper."] {
spawn_text(parent, &font_assets, txt);
}

parent.spawn(UiButton {
action: UiButtonAction::ChangeState(AppState::Game),
primary: true,
text: "play".into(),
margin: None,
});
});
}

fn spawn_text(parent: &mut ChildBuilder, font_assets: &FontAssets, txt: &str) {
parent.spawn(TextBundle {
text: Text::from_section(
txt,
TextStyle {
font: font_assets.menu.clone(),
font_size: 22.0,
color: COL_TEXT,
},
)
.with_alignment(TextAlignment::Center),
style: Style {
margin: UiRect::bottom(Val::Px(15.)),
..default()
},
..default()
});
}

0 comments on commit fcaea74

Please sign in to comment.