diff --git a/assets/level.blend b/assets/level.blend index 147ee84..c7cf0b1 100644 Binary files a/assets/level.blend and b/assets/level.blend differ diff --git a/assets/main.assets.ron b/assets/main.assets.ron index f7b7b12..f9a63ec 100644 --- a/assets/main.assets.ron +++ b/assets/main.assets.ron @@ -1,3 +1,4 @@ ({ "lebron": File (path: "images/KingLebron.png"), + "wall": File (path: "meshes/wall.glb"), }) diff --git a/assets/meshes/wall.glb b/assets/meshes/wall.glb new file mode 100644 index 0000000..0ff4c63 Binary files /dev/null and b/assets/meshes/wall.glb differ diff --git a/src/asset_loading/mod.rs b/src/asset_loading/mod.rs index 7572579..cee0105 100644 --- a/src/asset_loading/mod.rs +++ b/src/asset_loading/mod.rs @@ -28,7 +28,10 @@ pub(super) fn plugin(app: &mut App) { pub(crate) struct AudioAssets {} #[derive(AssetCollection, Resource, Clone)] -pub(crate) struct GltfAssets {} +pub(crate) struct GltfAssets { + #[asset(key = "wall")] + pub(crate) wall: Handle, +} #[derive(AssetCollection, Resource, Clone)] pub(crate) struct TextureAssets {} diff --git a/src/level_instantiation/mod.rs b/src/level_instantiation/mod.rs new file mode 100644 index 0000000..bf7218a --- /dev/null +++ b/src/level_instantiation/mod.rs @@ -0,0 +1,19 @@ +use bevy::prelude::*; + +use crate::{asset_loading::GltfAssets, GameState}; + +pub fn map_plugin(app: &mut App) { + // app.add_systems(OnEnter(GameState::Playing), spawn_level); +} + +fn spawn_level( + mut commands: Commands, + models: Res>, + gltf_assets: Res) { + let gltf = models.get(&gltf_assets.wall).unwrap(); + + // commands.spawn(SceneBundle { + // scene: gltf.scenes[0].clone(), + // ..default() + // }); +} diff --git a/src/main.rs b/src/main.rs index bd8733a..7abcb67 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +use std::default; + use asset_loading::ImageAssets; use bevy::prelude::*; use player_plugin::PlayerPlugin; @@ -6,18 +8,25 @@ use physics_plugin::PhysicsPlugin; mod asset_loading; mod player_plugin; mod physics_plugin; +mod level_instantiation; +mod main_menu; fn main() { App::new() - .add_plugins((DefaultPlugins, asset_loading::plugin, PlayerPlugin, PhysicsPlugin)) .init_state::() - // We need to register components to make them visible to Blenvy + .add_plugins(( + DefaultPlugins, + asset_loading::plugin, + PlayerPlugin, + PhysicsPlugin, + level_instantiation::map_plugin, + main_menu::plugin + )) .add_systems(Startup, setup) - .add_systems(OnExit(GameState::Loading), debug_our_king) .run(); } -#[derive(States, Default, Clone, Eq, PartialEq, Debug, Hash)] +#[derive(States, Debug, Clone, Copy, Eq, PartialEq, Hash, Default)] enum GameState { /// During the loading State the loading_plugin will load our assets #[default] diff --git a/src/main_menu.rs b/src/main_menu.rs new file mode 100644 index 0000000..8c5c4b1 --- /dev/null +++ b/src/main_menu.rs @@ -0,0 +1,142 @@ +use bevy::{color::palettes::css::{BLACK, CRIMSON, DARK_GREY}, prelude::*}; + +use crate::GameState; + +#[derive(Component)] +struct OnMainMenuScreen; + +pub fn plugin(app: &mut App) { + app + .add_systems(OnEnter(GameState::Menu), setup_main_menu) + .add_systems(OnExit(GameState::Menu), despawn_screen::) + .add_systems(Update, button_system.run_if(in_state(GameState::Menu))); +} + +#[derive(Component)] +struct MainMenu; + +#[derive(Component)] +enum MenuButton { + Play, + Settings, + Quit +} + +const TEXT_COLOR: Color = Color::srgb(0.9, 0.9, 0.9); + +const NORMAL_BUTTON: Color = Color::srgb(0.15, 0.15, 0.15); +const HOVERED_BUTTON: Color = Color::srgb(0.25, 0.25, 0.25); +const HOVERED_PRESSED_BUTTON: Color = Color::srgb(0.25, 0.65, 0.25); +const PRESSED_BUTTON: Color = Color::srgb(0.35, 0.75, 0.35); + +fn setup_main_menu(mut commands: Commands) { + let button_node = Node { + width: Val::Px(300.0), + height: Val::Px(65.0), + margin: UiRect::all(Val::Px(20.0)), + justify_content: JustifyContent::Center, + align_items: AlignItems::Center, + ..default() + }; + + let button_text_font = TextFont { + font_size: 33.0, + ..default() + }; + + commands + .spawn(( + Node { + width: Val::Percent(100.0), + height: Val::Percent(100.0), + flex_direction: FlexDirection::Column, + align_items: AlignItems::Center, + justify_content: JustifyContent::Center, + ..default() + }, + OnMainMenuScreen + )) + .insert(MainMenu) + .with_children(|parent| { + parent.spawn(( + Node { + flex_direction: FlexDirection::Column, + align_items: AlignItems::Center, + ..default() + }, + BackgroundColor(BLACK.into()), + )) + .with_children(|parent| { + // Display the game name + parent.spawn(( + Text::new("Among Me"), + TextFont { + font_size: 67.0, + ..default() + }, + TextColor(TEXT_COLOR), + Node { + margin: UiRect::all(Val::Px(50.0)), + ..default() + }, + )); + + // Display three buttons for each action available from the main menu: + // - new game + // - settings + // - quit + parent + .spawn(( + Button, + button_node.clone(), + BackgroundColor(NORMAL_BUTTON), + MenuButton::Play, + )) + .with_children(|parent| { + parent.spawn(( + Text::new("New Game"), + button_text_font.clone(), + TextColor(TEXT_COLOR), + )); + }); + parent + .spawn(( + Button, + button_node.clone(), + BackgroundColor(NORMAL_BUTTON), + MenuButton::Quit, + )) + .with_children(|parent| { + parent.spawn(( + Text::new("Quit"), + button_text_font.clone(), + TextColor(TEXT_COLOR), + )); + }); + }); + }); +} + +fn button_system( + mut interaction_query: Query< + (&Interaction, &MenuButton), + (Changed, With