diff --git a/assets/textures/grass_tile_64.png b/assets/textures/grass_tile_64.png new file mode 100644 index 0000000..722a756 Binary files /dev/null and b/assets/textures/grass_tile_64.png differ diff --git a/src/main.rs b/src/main.rs index f5511e5..337c777 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,9 @@ mod projectile; mod physics; -mod menu; -mod pause; mod bird; mod util; mod level; +mod ui; use std::path::PathBuf; @@ -14,8 +13,7 @@ use clap::{Parser, ValueEnum}; use level::LevelPlugin; use physics::PhysicsPlugin; use projectile::{ProjectileLauncher, ProjectilePlugin}; -use menu::MenuPlugin; -use pause::PausePlugin; +use ui::UiPlugin; #[derive(Parser, Debug)] #[clap(author, version, about, long_about = None)] @@ -59,20 +57,18 @@ fn main() { },), PhysicsPlugin, ProjectilePlugin, - MenuPlugin, - PausePlugin, BirdPlugin, + UiPlugin, match args.level { Some(level) => LevelPlugin { default_level: PathBuf::from(level) }, None => LevelPlugin::default() } )); app.add_systems(Startup, setup_sys); - app.add_systems(Update, (( - player_move_sys, - pause_menu_listener_sys - ).run_if(in_state(GameState::Game)), -)); + app.add_systems(Update, + (player_move_sys) + .run_if(in_state(GameState::Game)), + ); app.init_state::(); if let Some(state) = args.initial_state { @@ -86,15 +82,11 @@ fn main() { pub(crate) enum GameState { Game, Pause, - #[default] Menu, + #[default] Splash, } -// a label component to tell us which things are loaded in the Game GameState -#[derive(Component)] -struct OnGameScreen; - #[derive(Component)] struct Player { health: i32 @@ -118,9 +110,7 @@ fn setup_sys( Mesh2d(meshes.add(Annulus::new(25.0, 50.0))), MeshMaterial2d(materials.add(Color::WHITE)), Transform::from_xyz(0., - window_height / 2. + 75., 0.), - OnGameScreen, )); - } fn player_move_sys( @@ -139,60 +129,4 @@ fn player_move_sys( player_tf.translation.x = (player_tf.translation.x + move_distance).min(width / 2.) } } -} - -fn pause_menu_listener_sys( - keys: Res>, - mut game_state: ResMut> -) { - if keys.just_pressed(KeyCode::Escape) { - game_state.set(GameState::Pause); - info!("game paused"); - } -} - -// fn pause_menu_listener_sys( -// keys: Res>, -// mut game_state: ResMut>, -// mut menu_state: ResMut> -// ) { -// if keys.just_pressed(KeyCode::Escape) { -// match game_state { -// GameState::Game => { -// game_state.set(GameState::Pause); -// info!("game state changed to paused!"); -// } -// GameState::Menu => { -// match menu_state { -// MenuState::MainMenu => { -// menu_state.set(MenuState::Disabled); -// game_state.set(GameState::Game); -// info!("menu state is now diabled, and game state is game"); -// } -// MenuState::Settings => { -// menu_state.set(MenuState::MainMenu); -// info!("menu state is now main menu"); -// } -// _ => { -// panic!("HOW DID WE GET HERE???"); -// } -// } -// } -// GameState::Pause => { -// info!("THIS NEEDS DOING YAS COME ON"); -// } -// GameState::Splash => { -// // do nothing lol -// info!("HAH silly, u can't exit the splash screen, just wait."); -// } -// } -// } -// } - -// stole this directly from an example but it seems a sensible way of removing -// unneeded Entities with a given Component indiscriminantly -fn despawn_screen(to_despawn: Query>, mut commands: Commands) { - for entity in &to_despawn { - commands.entity(entity).despawn_recursive(); - } -} +} \ No newline at end of file diff --git a/src/menu.rs b/src/menu.rs deleted file mode 100644 index a6099e6..0000000 --- a/src/menu.rs +++ /dev/null @@ -1,302 +0,0 @@ -use bevy::{prelude::*}; -use std::{path::PathBuf}; -use super::{despawn_screen, pause_menu_listener_sys, GameState}; - -pub struct MenuPlugin; - -impl Plugin for MenuPlugin { - fn build(&self, app: &mut App) { - app - // when we enter Menu GameState, spawn in the menu items - .init_state::() - // handle stuff about whether we are in the menu GameState - .add_systems(OnEnter(GameState::Menu), menu_setup_sys) - .add_systems(Update, ( - button_color_sys, -// pause_menu_listener_sys, // uncomment once u certralise the logic for this - menu_button_action_sys - ).run_if(in_state(GameState::Menu))) - .add_systems(OnExit(GameState::Menu), despawn_screen::) - // handle the Main Menu gubbins - .add_systems(OnEnter(MenuState::MainMenu), main_menu_setup_sys) - .add_systems(OnExit(MenuState::MainMenu), despawn_screen::) - // handle the settings screen gubbins - .add_systems(OnEnter(MenuState::Settings), settings_menu_setup_sys) - .add_systems(OnExit(MenuState::Settings), despawn_screen::); - } -} - -// this is a tag component, so that we know what is on the menu screen -#[derive(Component)] -struct OnMenuScreen; - -#[derive(Component)] -struct OnMainMenuScreen; - -#[derive(Component)] -struct OnSettingsMenuScreen; - -// define the menu states -#[derive(Clone, Copy, Default, Eq, PartialEq, Debug, Hash, States)] -pub enum MenuState { - MainMenu, - Settings, - #[default] - Disabled -} - -// all the actions that a menu button can possibly do -#[derive(Component)] -enum MenuButtonAction { - Settings, - BackToMainMenu, - NewGame, - Quit -} - -// set some color constants -- eventually this can maybe be configurable? -// this doestnt work and idk why yet -// const BUTTON_DEFAULT_COLOR: Color = Color::srgb_u8(49, 104, 65); -// const BUTTON_HOVER_COLOR: Color = Color::srgb_u8(49, 104, 93); -// const BUTTON_PRESSED_COLOR: Color = Color::srgb_u8(49, 104, 120); - -const BUTTON_DEFAULT_COLOR: Color = Color::srgb(0.15, 0.15, 0.15); -const BUTTON_HOVER_COLOR: Color = Color::srgb(0.30, 0.30, 0.30); -const BUTTON_PRESSED_COLOR: Color = Color::srgb(0.45, 0.45, 0.45); - -const TEXT_COLOR: Color = Color::srgb(0.9, 0.9, 0.9); - - -fn button_color_sys( - mut interaction_query: Query< - ( - &Interaction, - &mut BackgroundColor, - ), - (Changed, With