From 26448cd0a0f0380bd3c98bce4d22c4593321f7be Mon Sep 17 00:00:00 2001 From: zefad Date: Fri, 18 Sep 2026 22:39:13 +0200 Subject: [PATCH] main menu --- src/main_menu.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/main_menu.rs diff --git a/src/main_menu.rs b/src/main_menu.rs new file mode 100644 index 0000000..73cb157 --- /dev/null +++ b/src/main_menu.rs @@ -0,0 +1,60 @@ +use bevy::prelude::*; + +use crate::game_state::GameState; + +// To delete menu's components +#[derive(Component)] +pub struct MainMenu; + +fn main_menu(mut commands: Commands) { + commands.spawn(( + MainMenu, + Node { + width: Val::Percent(100.0), + height: Val::Percent(100.0), + justify_content: JustifyContent::Center, + align_items: AlignItems::Center, + flex_direction: FlexDirection::Column, + row_gap: Val::Px(30.0), + ..default() + }, + children![ + ( + Text::new("DOWN INTO THE VOID"), + TextFont { + font_size: FontSize::Px(120.0), + ..default() + }, + ), + ( + Text::new("Press Enter to fall into the void"), + TextFont { + font_size: FontSize::Px(40.0), + ..default() + } + ) + ], + )); +} + +fn cleanup_menu(mut commands: Commands, menu: Query>) { + for entity in menu { + commands.entity(entity).despawn(); + } +} + +fn menu_input(input: Res>, mut next_state: ResMut>) { + if input.just_pressed(KeyCode::Enter) { + next_state.set(GameState::InGame); + } +} + +pub struct MainMenuPlugin; + +impl Plugin for MainMenuPlugin { + fn build(&self, app: &mut App) { + app.add_systems(OnEnter(GameState::MainMenu), main_menu) + .add_systems(Update, menu_input.run_if(in_state(GameState::MainMenu))) + .add_systems(OnExit(GameState::MainMenu), cleanup_menu); + } +}