Skip to content

Commit

Permalink
feat: main menu with graphics 🛶
Browse files Browse the repository at this point in the history
fix: splash screen
  • Loading branch information
eerii committed Dec 11, 2023
1 parent 2c7ed25 commit d88deab
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ a game for the bevy jam 4
- [ ] new features (lun)
- [x] end screen (win/lose)
- [x] restart game
- [ ] main menu with image
- [x] main menu with image
- [ ] sound and music
- [ ] other river types + bridges
- [ ] other spirit behaviour
Expand Down
Binary file added assets/icons/start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/sprites/explosion_kenney.png
Binary file not shown.
Binary file removed assets/sprites/patterns_kenney.png
Binary file not shown.
Binary file modified assets/sprites/river_stix.aseprite
Binary file not shown.
Binary file modified assets/sprites/river_stix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/sprites/ui_kenney.png
Binary file not shown.
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ pub struct ColorPalette {
impl Default for ColorPalette {
fn default() -> Self {
Self {
light: Color::rgb(225.0 / 255.0, 224.0 / 255.0, 122.0 / 255.0),
mid: Color::rgb(175.0 / 255.0, 204.0 / 255.0, 90.0 / 255.0),
light: Color::rgb(225.0 / 255.0, 224.0 / 255.0, 160.0 / 255.0),
mid: Color::rgb(175.0 / 255.0, 224.0 / 255.0, 150.0 / 255.0),
dark: Color::rgb(18.0 / 255.0, 13.0 / 255.0, 26.0 / 255.0),
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct DebugPlugin;
// Only debug implementation
#[cfg(debug_assertions)]
mod only_in_debug {
use crate::{load::GameAssets, ui::*, GameState};
use crate::{load::StartAssets, ui::*, GameState};
use bevy::{
diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin},
ecs::schedule::ScheduleLabel,
Expand Down Expand Up @@ -69,7 +69,7 @@ mod only_in_debug {
fn init_fps(
mut cmd: Commands,
node: Query<Entity, With<UiNode>>,
assets: Res<GameAssets>,
assets: Res<StartAssets>,
fps: Query<Entity, With<FpsText>>,
) {
if fps.iter().next().is_some() {
Expand Down
4 changes: 2 additions & 2 deletions src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ use crate::{

//0, 1, 2, 3, 4, 5, 130, 160, 250, 300, 400, 500, 700, 900, 1200, 1500, 2000, 2500, 3500,
const START_SCORES: [u32; 20] = [
0, 5, 30, 50, 70, 100, 130, 160, 250, 300, 400, 500, 700, 900, 1200, 1500, 2000, 2500, 3500,
0, 5, 30, 50, 100, 130, 160, 220, 260, 300, 400, 500, 700, 900, 1200, 1500, 2000, 2500, 3500,
5000,
];

const END_SCORES: [u32; 6] = [0, 60, 120, 350, 1000, 3000];
const END_SCORES: [u32; 6] = [0, 70, 200, 350, 1000, 3000];

pub struct CharonPlugin;

Expand Down
6 changes: 3 additions & 3 deletions src/hud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct TilesText;

fn init_hud(
mut cmd: Commands,
assets: Res<GameAssets>,
game_assets: Res<GameAssets>,
style: Res<UIStyle>,
mut node: Query<Entity, With<UiNode>>,
) {
Expand All @@ -66,7 +66,7 @@ fn init_hud(
tiles.spawn((
ImageBundle {
image: UiImage {
texture: assets.river_icon.clone(),
texture: game_assets.river_icon.clone(),
..default()
},
style: Style {
Expand Down Expand Up @@ -101,7 +101,7 @@ fn init_hud(
score.spawn((
ImageBundle {
image: UiImage {
texture: assets.coin_icon.clone(),
texture: game_assets.coin_icon.clone(),
..default()
},
style: Style {
Expand Down
25 changes: 17 additions & 8 deletions src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ pub struct LoadPlugin;
impl Plugin for LoadPlugin {
fn build(&self, app: &mut App) {
app.add_loading_state(LoadingState::new(GameState::Loading))
.init_collection::<GameAssets>()
.init_collection::<StartAssets>()
.add_collection_to_loading_state::<_, GameAssets>(GameState::Loading)
.add_collection_to_loading_state::<_, SpiritAssets>(GameState::Loading)
.add_collection_to_loading_state::<_, TilemapAssets>(GameState::Loading)
.add_plugins((ProgressPlugin::new(GameState::Loading)
.continue_to(GameState::Menu)
.track_assets(),))
.add_systems(OnEnter(GameState::Loading), init_splash)
.add_systems(Update, init_splash.run_if(in_state(GameState::Loading)))
.add_systems(OnExit(GameState::Loading), clear_loading)
.add_systems(
Update,
Expand All @@ -45,18 +46,24 @@ impl Plugin for LoadPlugin {
// Assets for the splash screen and menus
// They are loaded inmediately after the app is fired, no effect on loading state
#[derive(AssetCollection, Resource)]
pub struct GameAssets {
pub struct StartAssets {
#[asset(path = "icons/bevy.png")]
pub bevy_icon: Handle<Image>,

#[asset(path = "fonts/sans.ttf")]
pub font: Handle<Font>,
}

#[derive(AssetCollection, Resource)]
pub struct GameAssets {
#[asset(path = "icons/start.png")]
pub start_screen: Handle<Image>,

#[asset(path = "sprites/coin.png")]
pub coin_icon: Handle<Image>,

#[asset(path = "sprites/river.png")]
pub river_icon: Handle<Image>,

#[asset(path = "fonts/sans.ttf")]
pub font: Handle<Font>,
}

#[derive(AssetCollection, Resource)]
Expand Down Expand Up @@ -93,13 +100,15 @@ struct ProgressBar;
fn init_splash(
mut cmd: Commands,
node: Query<Entity, With<UiNode>>,
assets: Res<GameAssets>,
assets: Res<StartAssets>,
mut has_init: Local<bool>,
) {
if *has_init {
return;
}

info!("ui");

if let Ok(node) = node.get_single() {
if let Some(mut node) = cmd.get_entity(node) {
node.with_children(|parent| {
Expand Down Expand Up @@ -139,7 +148,7 @@ fn check_splash_finished(time: Res<Time>, mut timer: Query<&mut SplashTimer>) ->
fn check_progress(
mut cmd: Commands,
progress: Option<Res<ProgressCounter>>,
assets: Res<GameAssets>,
assets: Res<StartAssets>,
timer: Query<&SplashTimer>,
node: Query<Entity, With<UiNode>>,
opts: Res<Persistent<GameOptions>>,
Expand Down
61 changes: 56 additions & 5 deletions src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use crate::{
config::{GameOptions, GameScore, Keybinds, Persistent, FONT_MULTIPLIERS, FONT_SIZES},
input::Bind,
load::GameAssets,
ui::*,
GameState,
};
Expand Down Expand Up @@ -93,13 +94,14 @@ pub enum MenuButton {
fn init_menu(
mut cmd: Commands,
style: Res<UIStyle>,
assets: Res<GameAssets>,
mut node: Query<Entity, With<UiNode>>,
score: Res<Persistent<GameScore>>,
) {
// Main menu layout
if let Ok(node) = node.get_single_mut() {
cmd.insert_resource(MenuStarting);
layout_main(cmd, node, &style, score.best_score);
layout_main(cmd, node, &style, score.best_score, &assets.start_screen);
}
}

Expand Down Expand Up @@ -197,6 +199,7 @@ fn may_be_cleaned(mut cmd: Commands, menu_starting: Option<Res<MenuStarting>>) {
fn clean_menu(
mut cmd: Commands,
state: Res<State<MenuState>>,
assets: Res<GameAssets>,
node: Query<Entity, With<UiNode>>,
style: Res<UIStyle>,
opts: Res<Persistent<GameOptions>>,
Expand All @@ -214,7 +217,9 @@ fn clean_menu(
entity.despawn_descendants();

match state.get() {
MenuState::Main => layout_main(cmd, node, &style, score.best_score),
MenuState::Main => {
layout_main(cmd, node, &style, score.best_score, &assets.start_screen)
}
MenuState::Settings => layout_options(cmd, node, &style),
MenuState::Keybinds => layout_keybinds(cmd, node, &style, &keybinds),
MenuState::Rebinding => {
Expand Down Expand Up @@ -316,18 +321,64 @@ fn remap_keybind(
// Extra
// ·····

fn layout_main(mut cmd: Commands, node: Entity, style: &UIStyle, best_score: u32) {
fn layout_main(
mut cmd: Commands,
node: Entity,
style: &UIStyle,
best_score: u32,
background: &Handle<Image>,
) {
if let Some(mut node) = cmd.get_entity(node) {
node.with_children(|parent| {
// Background image
parent.spawn((
ImageBundle {
image: UiImage {
texture: background.clone(),
..default()
},
style: Style {
width: Val::Percent(100.),
height: Val::Percent(100.),
position_type: PositionType::Absolute,
top: Val::Px(0.),
left: Val::Px(0.),
..default()
},
..default()
},
UI_LAYER,
));

UIText::simple(style, "Entities' repose")
.with_title()
.add(parent);
if best_score > 0 {
UIText::simple(style, &format!("Most saved: {}", best_score)).add(parent);
}

UIButton::new(style, "Play", Some(MenuButton::Play)).add(parent);
UIButton::new(style, "Settings", Some(MenuButton::GoSettings)).add(parent);
parent
.spawn((
NodeBundle {
style: Style {
flex_direction: FlexDirection::Row,
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
column_gap: Val::Px(32.),
padding: UiRect {
bottom: Val::Percent(45.),
..default()
},
..default()
},
..default()
},
UI_LAYER,
))
.with_children(|parent| {
UIButton::new(style, "Play", Some(MenuButton::Play)).add(parent);
UIButton::new(style, "Settings", Some(MenuButton::GoSettings)).add(parent);
});
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/spirits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rand::Rng;

use crate::{
config::GameScore,
load::{GameAssets, SpiritAssets},
load::{SpiritAssets, StartAssets},
tilemap::{
get_neighbours, pos_to_tile, tile_to_pos, EndTile, PathTile, StartTile, TilemapLayer,
},
Expand Down Expand Up @@ -174,7 +174,7 @@ fn spawn_spirit(
fn check_lose_count(
mut cmd: Commands,
mut state: ResMut<NextState<GameState>>,
assets: Res<GameAssets>,
assets: Res<StartAssets>,
mut start: Query<(&TilePos, &mut StartTile)>,
mut text: Query<&mut Text, With<LoseText>>,
tilemap: Query<(&TilemapLayer, &TilemapGridSize, &TilemapType, &Transform)>,
Expand Down
4 changes: 2 additions & 2 deletions src/ui.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy::{prelude::*, render::view::RenderLayers, sprite::MaterialMesh2dBundle};
use bevy_persistent::Persistent;

use crate::{config::GameOptions, load::GameAssets, GameState};
use crate::{config::GameOptions, load::StartAssets, GameState};

pub const UI_LAYER: RenderLayers = RenderLayers::layer(1);
const MENU_WIDTH: Val = Val::Px(300.);
Expand Down Expand Up @@ -108,7 +108,7 @@ pub fn init_ui(
fn change_style(
mut style: ResMut<UIStyle>,
opts: Res<Persistent<GameOptions>>,
assets: Res<GameAssets>,
assets: Res<StartAssets>,
) {
style.title = TextStyle {
font: assets.font.clone(),
Expand Down

0 comments on commit d88deab

Please sign in to comment.