game over
This commit is contained in:
+13
-6
@@ -27,7 +27,7 @@ fn game_over(mut commands: Commands) {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
Text::new("Press N for new map or R to restart"),
|
Text::new("| N new map | R restart | T main menu | "),
|
||||||
TextFont {
|
TextFont {
|
||||||
font_size: FontSize::Px(40.0),
|
font_size: FontSize::Px(40.0),
|
||||||
..default()
|
..default()
|
||||||
@@ -37,21 +37,28 @@ fn game_over(mut commands: Commands) {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cleanup_game_over(mut commands: Commands, menu: Query<Entity, With<MainMenu>>) {
|
fn cleanup_game_over(mut commands: Commands, game_over: Query<Entity, With<GameOver>>) {
|
||||||
for entity in menu {
|
for entity in game_over {
|
||||||
commands.entity(entity).despawn();
|
commands.entity(entity).despawn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn game_over_input(input: Res<ButtonInput<KeyCode>>, mut next_state: ResMut<NextState<GameState>>) {
|
fn game_over_input(input: Res<ButtonInput<KeyCode>>, mut next_state: ResMut<NextState<GameState>>) {
|
||||||
if input.just_pressed(KeyCode::Enter) {
|
if input.just_pressed(KeyCode::KeyN) {
|
||||||
|
// TODO: Restart with completely reseting the game state (OnEnter maybe)
|
||||||
next_state.set(GameState::InGame);
|
next_state.set(GameState::InGame);
|
||||||
|
} else if input.just_pressed(KeyCode::KeyR) {
|
||||||
|
// TODO: restart with the same seed
|
||||||
|
next_state.set(GameState::InGame);
|
||||||
|
} else if input.just_pressed(KeyCode::KeyT) {
|
||||||
|
// TODO: Clear all of the game asset (OnExit)
|
||||||
|
next_state.set(GameState::MainMenu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MainMenuPlugin;
|
pub struct GameOverPlugin;
|
||||||
|
|
||||||
impl Plugin for MainMenuPlugin {
|
impl Plugin for GameOverPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(OnEnter(GameState::GameOver), game_over)
|
app.add_systems(OnEnter(GameState::GameOver), game_over)
|
||||||
.add_systems(
|
.add_systems(
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use crate::bounds::BoundsPlugin;
|
|||||||
use crate::camera::CameraPlugin;
|
use crate::camera::CameraPlugin;
|
||||||
use crate::collision::CollisionPlugin;
|
use crate::collision::CollisionPlugin;
|
||||||
use crate::debug::DebugPlugin;
|
use crate::debug::DebugPlugin;
|
||||||
|
use crate::game_over::GameOverPlugin;
|
||||||
use crate::game_state::GameStatePlugin;
|
use crate::game_state::GameStatePlugin;
|
||||||
use crate::main_menu::MainMenuPlugin;
|
use crate::main_menu::MainMenuPlugin;
|
||||||
use crate::player::PlayerPlugin;
|
use crate::player::PlayerPlugin;
|
||||||
@@ -43,5 +44,6 @@ fn main() {
|
|||||||
.add_plugins(DebugPlugin) // Debug
|
.add_plugins(DebugPlugin) // Debug
|
||||||
.add_plugins(GameStatePlugin) // Game states
|
.add_plugins(GameStatePlugin) // Game states
|
||||||
.add_plugins(MainMenuPlugin) // Main Menu
|
.add_plugins(MainMenuPlugin) // Main Menu
|
||||||
|
.add_plugins(GameOverPlugin) // GameOver
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ pub fn reset_player(
|
|||||||
mut has_collided: ResMut<HasCollided>,
|
mut has_collided: ResMut<HasCollided>,
|
||||||
mut fall_started: ResMut<FallStarted>,
|
mut fall_started: ResMut<FallStarted>,
|
||||||
// mut regenerate_obstacles: ResMut<RegenerateObstacles>,
|
// mut regenerate_obstacles: ResMut<RegenerateObstacles>,
|
||||||
|
mut next_state: ResMut<NextState<GameState>>, // For debug gameover state
|
||||||
) {
|
) {
|
||||||
let (mut transform, mut velocity, mut sprite) = player.into_inner();
|
let (mut transform, mut velocity, mut sprite) = player.into_inner();
|
||||||
|
|
||||||
@@ -104,6 +105,9 @@ pub fn reset_player(
|
|||||||
fall_started.0 = false;
|
fall_started.0 = false;
|
||||||
// TODO: uncomment when obstacle chunk logic is implemented
|
// TODO: uncomment when obstacle chunk logic is implemented
|
||||||
// regenerate_obstacles.0 = true;
|
// regenerate_obstacles.0 = true;
|
||||||
|
} else if input.just_pressed(KeyCode::KeyG) {
|
||||||
|
// Temporary test for gameover state
|
||||||
|
next_state.set(GameState::GameOver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user