game over rs

This commit is contained in:
2026-09-18 22:42:46 +02:00
parent 8d496eee73
commit 87c39820d7
2 changed files with 64 additions and 0 deletions
+63
View File
@@ -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<Entity, With<MainMenu>>) {
for entity in menu {
commands.entity(entity).despawn();
}
}
fn game_over_input(input: Res<ButtonInput<KeyCode>>, mut next_state: ResMut<NextState<GameState>>) {
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);
}
}
+1
View File
@@ -15,6 +15,7 @@ mod bounds;
mod camera; mod camera;
mod collision; mod collision;
mod debug; mod debug;
mod game_over;
mod game_state; mod game_state;
mod main_menu; mod main_menu;
mod obstacle; mod obstacle;