Compare commits
2 Commits
cf9825fcc3
...
c0cf6d7f30
| Author | SHA1 | Date | |
|---|---|---|---|
| c0cf6d7f30 | |||
| cc23e9e08e |
@@ -51,6 +51,7 @@ impl Plugin for AsteroidPlugin {
|
||||
.init_resource::<GameAssets>()
|
||||
.add_systems(Startup, spawn_camera)
|
||||
.add_systems(OnEnter(GameState::Playing), objects::spawn_player)
|
||||
.add_systems(OnExit(GameState::Playing), despawn::<Ship>)
|
||||
.add_systems(
|
||||
FixedUpdate,
|
||||
(
|
||||
@@ -84,6 +85,14 @@ impl Plugin for AsteroidPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
/// Despawns entities matching the generic argument. Intended to remove UI
|
||||
/// elements.
|
||||
pub(crate) fn despawn<T: Component>(mut commands: Commands, to_despawn: Query<Entity, With<T>>) {
|
||||
for entity in to_despawn {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
}
|
||||
|
||||
/// The game's main state tracking mechanism, registered with Bevy as a [`State`](`bevy::prelude::State`).
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, States)]
|
||||
pub enum GameState {
|
||||
|
||||
@@ -3,6 +3,7 @@ use std::ops::DerefMut;
|
||||
use crate::{
|
||||
GameState,
|
||||
config::{UI_BUTTON_HOVERED, UI_BUTTON_NORMAL, UI_BUTTON_PRESSED},
|
||||
despawn,
|
||||
resources::{Lives, Score},
|
||||
};
|
||||
|
||||
@@ -105,14 +106,6 @@ struct CountdownText;
|
||||
#[derive(Component)]
|
||||
struct CountdownBar;
|
||||
|
||||
/// Despawns entities matching the generic argument. Intended to remove UI
|
||||
/// elements.
|
||||
fn despawn<T: Component>(mut commands: Commands, to_despawn: Query<Entity, With<T>>) {
|
||||
for entity in to_despawn {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
}
|
||||
|
||||
/// Utility function for creating a standard button.
|
||||
fn button_bundle(text: &str) -> impl Bundle {
|
||||
(
|
||||
@@ -169,7 +162,8 @@ fn spawn_menu(mut commands: Commands) {
|
||||
});
|
||||
}
|
||||
|
||||
fn spawn_get_ready(mut commands: Commands) {
|
||||
fn spawn_get_ready(mut commands: Commands, mut timer: ResMut<ReadySetGoTimer>) {
|
||||
timer.reset();
|
||||
commands.spawn((
|
||||
OnReadySetGo, // marker, so this can be de-spawned properly
|
||||
Node {
|
||||
|
||||
Reference in New Issue
Block a user