diff --git a/src/lib.rs b/src/lib.rs index 51ef7cf..e174a83 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,8 +34,8 @@ pub struct AsteroidPlugin; impl Plugin for AsteroidPlugin { fn build(&self, app: &mut App) { app.add_plugins(( - widgets::GameMenuPlugin, - widgets::preparation_widget_plugin, + widgets::PluginGameMenu, + widgets::PluginGetReady, RapierPhysicsPlugin::::pixels_per_meter(10.0), RapierDebugRenderPlugin::default(), )) diff --git a/src/widgets.rs b/src/widgets.rs index c9b898e..ecbae9b 100644 --- a/src/widgets.rs +++ b/src/widgets.rs @@ -8,21 +8,42 @@ use bevy::{ prelude::*, }; -pub fn spawn_ui(mut commands: Commands, score: Res, lives: Res) { - commands.spawn(( - Text::new(format!("Score: {score:?} | Lives: {lives:?}")), - TextFont::from_font_size(25.0), - )); +/// Plugin for the main menu +pub struct PluginGameMenu; + +impl Plugin for PluginGameMenu { + fn build(&self, app: &mut App) { + app.add_systems(OnEnter(GameState::TitleScreen), spawn_menu) + .add_systems(OnExit(GameState::TitleScreen), despawn_menu) + .add_systems( + Update, + handle_spacebar.run_if(in_state(GameState::TitleScreen)), + ); + } } -pub fn preparation_widget_plugin(app: &mut App) { - app.add_systems(OnEnter(GameState::GetReady), spawn_get_ready) - .add_systems(OnExit(GameState::GetReady), despawn_get_ready) - .add_systems( - Update, - (animate_get_ready_widget).run_if(in_state(GameState::GetReady)), - ) - .insert_resource(ReadySetGoTimer(Timer::from_seconds(3.0, TimerMode::Once))); +/// Plugin for the "get ready" period as gameplay starts. +pub struct PluginGetReady; + +impl Plugin for PluginGetReady { + fn build(&self, app: &mut App) { + app.add_systems(OnEnter(GameState::GetReady), spawn_get_ready) + .add_systems(OnExit(GameState::GetReady), despawn_get_ready) + .add_systems( + Update, + (animate_get_ready_widget).run_if(in_state(GameState::GetReady)), + ) + .insert_resource(ReadySetGoTimer(Timer::from_seconds(3.0, TimerMode::Once))); + } +} + +/// Plugin for the game-over screen (TODO) +pub struct PluginGameOver; + +impl Plugin for PluginGameOver { + fn build(&self, app: &mut App) { + todo!(); + } } /// Marker component for things on the get-ready indicator @@ -108,19 +129,6 @@ fn animate_get_ready_widget( } } -pub struct GameMenuPlugin; - -impl Plugin for GameMenuPlugin { - fn build(&self, app: &mut App) { - app.add_systems(OnEnter(GameState::TitleScreen), spawn_menu) - .add_systems(OnExit(GameState::TitleScreen), despawn_menu) - .add_systems( - Update, - handle_spacebar.run_if(in_state(GameState::TitleScreen)), - ); - } -} - // 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)] @@ -158,3 +166,10 @@ fn handle_spacebar(input: Res>, mut game_state: ResMut, lives: Res) { + commands.spawn(( + Text::new(format!("Score: {score:?} | Lives: {lives:?}")), + TextFont::from_font_size(25.0), + )); +}