main menu
This commit is contained in:
@@ -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<Entity, With<MainMenu>>) {
|
||||
for entity in menu {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
}
|
||||
|
||||
fn menu_input(input: Res<ButtonInput<KeyCode>>, mut next_state: ResMut<NextState<GameState>>) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user