From 87c39820d7b33462db00e3b9b5cd9948443a525e Mon Sep 17 00:00:00 2001 From: zefad Date: Fri, 18 Sep 2026 22:42:46 +0200 Subject: [PATCH] game over rs --- src/game_over.rs | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 1 + 2 files changed, 64 insertions(+) create mode 100644 src/game_over.rs diff --git a/src/game_over.rs b/src/game_over.rs new file mode 100644 index 0000000..b9fed19 --- /dev/null +++ b/src/game_over.rs @@ -0,0 +1,63 @@ +use bevy::prelude::*; + +use crate::game_state::GameState; + +// To delete game over's components +#[derive(Component)] +pub struct GameOver; + +fn game_over(mut commands: Commands) { + commands.spawn(( + GameOver, + 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("GAME OVER"), + TextFont { + font_size: FontSize::Px(120.0), + ..default() + }, + ), + ( + Text::new("Press N for new map or R to restart"), + TextFont { + font_size: FontSize::Px(40.0), + ..default() + } + ) + ], + )); +} + +fn cleanup_game_over(mut commands: Commands, menu: Query>) { + for entity in menu { + commands.entity(entity).despawn(); + } +} + +fn game_over_input(input: Res>, mut next_state: ResMut>) { + 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::GameOver), game_over) + .add_systems( + Update, + game_over_input.run_if(in_state(GameState::GameOver)), + ) + .add_systems(OnExit(GameState::GameOver), cleanup_game_over); + } +} diff --git a/src/main.rs b/src/main.rs index 1064cc7..fa5f866 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,7 @@ mod bounds; mod camera; mod collision; mod debug; +mod game_over; mod game_state; mod main_menu; mod obstacle;