Signed-off-by: Harald Hoyer <harald@hoyer.xyz>
This commit is contained in:
Harald Hoyer 2025-04-11 10:43:25 +02:00
parent ef055fe3c5
commit 3dbfb9dac1
11 changed files with 1085 additions and 867 deletions

68
src/game_state.rs Normal file
View file

@ -0,0 +1,68 @@
use bevy::prelude::*;
use crate::components::{Bullet, Enemy, GameOverUI}; // Import necessary components
// --- Game States ---
#[derive(Clone, Eq, PartialEq, Debug, Hash, Default, States)]
pub enum AppState {
#[default]
Playing,
GameOver,
}
// --- Game Over UI ---
pub fn setup_game_over_ui(mut commands: Commands) {
println!("Entering GameOver state. Setting up UI.");
commands.spawn((
TextBundle::from_section(
"GAME OVER",
TextStyle {
font_size: 100.0,
color: Color::WHITE,
..default()
},
)
.with_style(Style {
position_type: PositionType::Absolute,
align_self: AlignSelf::Center,
justify_self: JustifySelf::Center,
top: Val::Percent(40.0), // Center vertically roughly
..default()
}),
GameOverUI, // Tag the UI element
));
// TODO: Add "Press R to Restart" text later
}
pub fn cleanup_game_over_ui(mut commands: Commands, query: Query<Entity, With<GameOverUI>>) {
println!("Exiting GameOver state. Cleaning up UI.");
for entity in query.iter() {
commands.entity(entity).despawn_recursive();
}
}
// --- Cleanup ---
// Cleanup system when exiting the Playing state
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_query: Query<Entity, With<Enemy>>,
// Optionally despawn player too, or handle separately if needed for restart
// player_query: Query<Entity, With<Player>>,
) {
println!("Exiting Playing state. Cleaning up game entities.");
for entity in bullet_query.iter() {
commands.entity(entity).despawn();
}
for entity in enemy_bullet_query.iter() { // Also despawn enemy bullets
commands.entity(entity).despawn();
}
for entity in enemy_query.iter() {
commands.entity(entity).despawn();
}
// for entity in player_query.iter() {
// commands.entity(entity).despawn();
// }
}