fix: remove orphaned duplicate code in cleanup_game_entities
This commit is contained in:
parent
28e4e53da9
commit
704a4476f0
1 changed files with 73 additions and 20 deletions
|
|
@ -1,5 +1,6 @@
|
|||
use crate::components::{Bullet, Enemy, GameOverUI, RestartMessage, StartButton, StartMenuUI};
|
||||
use crate::resources::RestartPressed;
|
||||
use bevy::prelude::*;
|
||||
use crate::components::{Bullet, Enemy, GameOverUI, StartMenuUI, StartButton}; // Import necessary components
|
||||
|
||||
// --- Game States ---
|
||||
#[derive(Clone, Eq, PartialEq, Debug, Hash, Default, States)]
|
||||
|
|
@ -27,19 +28,43 @@ pub fn setup_game_over_ui(mut commands: Commands) {
|
|||
position_type: PositionType::Absolute,
|
||||
align_self: AlignSelf::Center,
|
||||
justify_self: JustifySelf::Center,
|
||||
top: Val::Percent(40.0), // Center vertically roughly
|
||||
top: Val::Percent(40.0),
|
||||
..default()
|
||||
}),
|
||||
GameOverUI, // Tag the UI element
|
||||
GameOverUI,
|
||||
));
|
||||
commands.spawn((
|
||||
TextBundle::from_section(
|
||||
"Press R to Restart",
|
||||
TextStyle {
|
||||
font_size: 32.0,
|
||||
color: Color::WHITE,
|
||||
..default()
|
||||
},
|
||||
)
|
||||
.with_style(Style {
|
||||
position_type: PositionType::Absolute,
|
||||
align_self: AlignSelf::Center,
|
||||
justify_self: JustifySelf::Center,
|
||||
top: Val::Percent(55.0),
|
||||
..default()
|
||||
}),
|
||||
RestartMessage,
|
||||
));
|
||||
// TODO: Add "Press R to Restart" text later
|
||||
}
|
||||
|
||||
pub fn cleanup_game_over_ui(mut commands: Commands, query: Query<Entity, With<GameOverUI>>) {
|
||||
pub fn cleanup_game_over_ui(
|
||||
mut commands: Commands,
|
||||
query: Query<Entity, With<GameOverUI>>,
|
||||
restart_query: Query<Entity, With<RestartMessage>>,
|
||||
) {
|
||||
println!("Exiting GameOver state. Cleaning up UI.");
|
||||
for entity in query.iter() {
|
||||
commands.entity(entity).despawn_recursive();
|
||||
}
|
||||
for entity in restart_query.iter() {
|
||||
commands.entity(entity).despawn_recursive();
|
||||
}
|
||||
}
|
||||
|
||||
// --- Cleanup ---
|
||||
|
|
@ -48,8 +73,9 @@ pub fn cleanup_game_over_ui(mut commands: Commands, query: Query<Entity, With<Ga
|
|||
pub fn cleanup_game_entities(
|
||||
mut commands: Commands,
|
||||
bullet_query: Query<Entity, With<Bullet>>,
|
||||
enemy_bullet_query: Query<Entity, With<crate::components::EnemyBullet>>, // Need to specify crate::components
|
||||
enemy_bullet_query: Query<Entity, With<crate::components::EnemyBullet>>,
|
||||
enemy_query: Query<Entity, With<Enemy>>,
|
||||
restart_message_query: Query<Entity, With<crate::components::RestartMessage>>,
|
||||
// Optionally despawn player too, or handle separately if needed for restart
|
||||
// player_query: Query<Entity, With<Player>>,
|
||||
) {
|
||||
|
|
@ -57,12 +83,15 @@ pub fn cleanup_game_entities(
|
|||
for entity in bullet_query.iter() {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
for entity in enemy_bullet_query.iter() { // Also despawn enemy bullets
|
||||
for entity in enemy_bullet_query.iter() {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
for entity in enemy_query.iter() {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
for entity in restart_message_query.iter() {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
// for entity in player_query.iter() {
|
||||
// commands.entity(entity).despawn();
|
||||
// }
|
||||
|
|
@ -91,17 +120,20 @@ pub fn setup_start_menu_ui(mut commands: Commands) {
|
|||
))
|
||||
.with_children(|parent| {
|
||||
// Title
|
||||
parent.spawn(TextBundle::from_section(
|
||||
parent.spawn(
|
||||
TextBundle::from_section(
|
||||
"BGLGA",
|
||||
TextStyle {
|
||||
font_size: 120.0,
|
||||
color: Color::WHITE,
|
||||
..default()
|
||||
},
|
||||
).with_style(Style {
|
||||
)
|
||||
.with_style(Style {
|
||||
margin: UiRect::bottom(Val::Px(50.0)),
|
||||
..default()
|
||||
}));
|
||||
}),
|
||||
);
|
||||
|
||||
// Start Game Button
|
||||
parent
|
||||
|
|
@ -163,3 +195,24 @@ pub fn start_menu_button_system(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_restart_input(
|
||||
mut keyboard_input: ResMut<Input<KeyCode>>,
|
||||
mut restart_resource: ResMut<RestartPressed>,
|
||||
mut app_state: ResMut<NextState<AppState>>,
|
||||
) {
|
||||
if keyboard_input.just_pressed(KeyCode::R) {
|
||||
restart_resource.pressed = true;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn restart_game_system(
|
||||
mut app_state: ResMut<NextState<AppState>>,
|
||||
mut restart_resource: ResMut<RestartPressed>,
|
||||
) {
|
||||
if restart_resource.pressed {
|
||||
println!("Restart requested. Transitioning to Playing state.");
|
||||
restart_resource.pressed = false;
|
||||
app_state.set(AppState::Playing);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue