Finally impl the "space to start" feature

This commit is contained in:
2025-07-27 10:39:10 -05:00
parent 7123192271
commit c11322969c

View File

@@ -7,7 +7,8 @@ pub struct GameMenuPlugin;
impl Plugin for GameMenuPlugin { impl Plugin for GameMenuPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_systems(OnEnter(GameState::TitleScreen), spawn_menu) app.add_systems(OnEnter(GameState::TitleScreen), spawn_menu)
.add_systems(OnExit(GameState::TitleScreen), despawn_menu); .add_systems(OnExit(GameState::TitleScreen), despawn_menu)
.add_systems(Update, handle_spacebar);
} }
} }
@@ -46,3 +47,12 @@ fn despawn_menu(
commands.entity(entity).despawn(); commands.entity(entity).despawn();
} }
} }
fn handle_spacebar(
input: Res<ButtonInput<KeyCode>>,
mut game_state: ResMut<NextState<GameState>>,
) {
if input.just_pressed(KeyCode::Space) {
game_state.set(GameState::Playing);
}
}