From f1142036656170fc1d370370e9042a35e3086e5d Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Fri, 29 Nov 2024 16:01:14 -0600 Subject: [PATCH] Title menu, but always present. Time for states! I've made a quick title menu, but it is always present. I'll need to set up some game state stuff so I can flip between play modes. --- src/lib.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 85d96f4..e4cfcae 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,7 @@ impl Plugin for AsteroidPlugin { fn build(&self, app: &mut App) { app.add_systems( Startup, - (spawn_camera, spawn_player, spawn_ui), + (spawn_camera, spawn_player, spawn_ui, start_screen), ) .insert_resource(ClearColor(BACKGROUND_COLOR)) .insert_resource(WorldSize { @@ -73,6 +73,11 @@ struct WorldSize { height: f32, } +// 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; + fn spawn_camera(mut commands: Commands) { commands.spawn(Camera2dBundle::default()); } @@ -243,3 +248,26 @@ fn spawn_ui(mut commands: Commands, score: Res, lives: Res) { ) ])); } + +fn start_screen(mut commands: Commands) { + commands.spawn(( + TitleUI, + TextBundle::from_sections([ + TextSection::new( + "Robert's Bad Asteroids Game", + TextStyle { + font_size: 50.0, + ..default() + }, + ), + TextSection::new( + "Press space to begin", + TextStyle { + font_size: 40.0, + ..default() + }, + ), + ]) + .with_text_justify(bevy::text::JustifyText::Center), + )); +} \ No newline at end of file