Rearrange the main menu components & systems
I'm trying to keep things somewhat in order. Plugins, then components, then systems. Within those, they're roughly ordered by game state.
This commit is contained in:
@@ -52,6 +52,11 @@ impl Plugin for PluginGameOver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Marker component for the title screen UI entity.
|
||||||
|
// This way, a query for the TitleUI can be used to despawn the title screen
|
||||||
|
#[derive(Component)]
|
||||||
|
struct TitleUI;
|
||||||
|
|
||||||
/// Marker component for things on the get-ready indicator
|
/// Marker component for things on the get-ready indicator
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
struct OnReadySetGo;
|
struct OnReadySetGo;
|
||||||
@@ -90,6 +95,27 @@ fn despawn<T: Component>(mut commands: Commands, to_despawn: Query<Entity, With<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn spawn_menu(mut commands: Commands) {
|
||||||
|
commands
|
||||||
|
.spawn((
|
||||||
|
TitleUI,
|
||||||
|
Node {
|
||||||
|
flex_direction: FlexDirection::Column,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.with_children(|cmds| {
|
||||||
|
cmds.spawn((
|
||||||
|
Text::new("Robert's Bad Asteroids Game"),
|
||||||
|
TextFont::from_font_size(50.0),
|
||||||
|
));
|
||||||
|
cmds.spawn((
|
||||||
|
Text::new("Press space to begin"),
|
||||||
|
TextFont::from_font_size(40.0),
|
||||||
|
));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
fn spawn_get_ready(mut commands: Commands) {
|
fn spawn_get_ready(mut commands: Commands) {
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
OnReadySetGo, // marker, so this can be de-spawned properly
|
OnReadySetGo, // marker, so this can be de-spawned properly
|
||||||
@@ -256,32 +282,7 @@ fn operate_gameover_ui(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Marker component for the title screen UI entity.
|
/// Main menu input listener. Starts game when the spacebar is pressed.
|
||||||
// This way, a query for the TitleUI can be used to despawn the title screen
|
|
||||||
#[derive(Component)]
|
|
||||||
struct TitleUI;
|
|
||||||
|
|
||||||
fn spawn_menu(mut commands: Commands) {
|
|
||||||
commands
|
|
||||||
.spawn((
|
|
||||||
TitleUI,
|
|
||||||
Node {
|
|
||||||
flex_direction: FlexDirection::Column,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
))
|
|
||||||
.with_children(|cmds| {
|
|
||||||
cmds.spawn((
|
|
||||||
Text::new("Robert's Bad Asteroids Game"),
|
|
||||||
TextFont::from_font_size(50.0),
|
|
||||||
));
|
|
||||||
cmds.spawn((
|
|
||||||
Text::new("Press space to begin"),
|
|
||||||
TextFont::from_font_size(40.0),
|
|
||||||
));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_spacebar(input: Res<ButtonInput<KeyCode>>, mut game_state: ResMut<NextState<GameState>>) {
|
fn handle_spacebar(input: Res<ButtonInput<KeyCode>>, mut game_state: ResMut<NextState<GameState>>) {
|
||||||
if input.just_pressed(KeyCode::Space) {
|
if input.just_pressed(KeyCode::Space) {
|
||||||
game_state.set(GameState::GetReady);
|
game_state.set(GameState::GetReady);
|
||||||
|
|||||||
Reference in New Issue
Block a user