properly reset generic asteroids on death

This commit is contained in:
yuni 2024-04-20 00:47:35 +02:00
parent 8c3eb72994
commit f1a7781fa2
2 changed files with 5 additions and 2 deletions

View file

@ -428,6 +428,7 @@ fn handle_player_death(
q_noscenes: Query<Entity, (With<world::DespawnOnPlayerDeath>, Without<SceneInstance>)>, q_noscenes: Query<Entity, (With<world::DespawnOnPlayerDeath>, Without<SceneInstance>)>,
ew_spawn: EventWriter<commands::SpawnEvent>, ew_spawn: EventWriter<commands::SpawnEvent>,
mut scene_spawner: ResMut<SceneSpawner>, mut scene_spawner: ResMut<SceneSpawner>,
mut active_asteroids: ResMut<world::ActiveAsteroids>,
mut ew_sfx: EventWriter<audio::PlaySfxEvent>, mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
mut ew_effect: EventWriter<effects::SpawnEffectEvent>, mut ew_effect: EventWriter<effects::SpawnEffectEvent>,
mut log: ResMut<hud::Log>, mut log: ResMut<hud::Log>,
@ -438,6 +439,7 @@ fn handle_player_death(
return; return;
} }
settings.reset_player_settings(); settings.reset_player_settings();
active_asteroids.0.clear();
for entity in &q_noscenes { for entity in &q_noscenes {
cmd.entity(entity).despawn(); cmd.entity(entity).despawn();
} }

View file

@ -78,14 +78,14 @@ impl Plugin for WorldPlugin {
#[derive(Resource)] struct AsteroidUpdateTimer(Timer); #[derive(Resource)] struct AsteroidUpdateTimer(Timer);
#[derive(Resource)] struct AsteroidDatabase(Vec<AsteroidData>); #[derive(Resource)] struct AsteroidDatabase(Vec<AsteroidData>);
#[derive(Resource)] struct ActiveAsteroids(HashMap<I64Vec3, AsteroidData>); #[derive(Resource)] pub struct ActiveAsteroids(pub HashMap<I64Vec3, AsteroidData>);
#[derive(Resource)] struct AsteroidModel1(Handle<Scene>); #[derive(Resource)] struct AsteroidModel1(Handle<Scene>);
#[derive(Resource)] struct AsteroidModel2(Handle<Scene>); #[derive(Resource)] struct AsteroidModel2(Handle<Scene>);
#[derive(Component)] struct Asteroid; #[derive(Component)] struct Asteroid;
#[derive(Component)] pub struct DespawnOnPlayerDeath; #[derive(Component)] pub struct DespawnOnPlayerDeath;
struct AsteroidData { pub struct AsteroidData {
entity: Entity, entity: Entity,
//viewdistance: f64, //viewdistance: f64,
} }
@ -342,6 +342,7 @@ fn spawn_despawn_asteroids(
Rotation::from(Quat::from_rotation_y(-PI / 3.)), Rotation::from(Quat::from_rotation_y(-PI / 3.)),
Position::new(pos), Position::new(pos),
Asteroid, Asteroid,
DespawnOnPlayerDeath,
)); ));
let model = match class { let model = match class {
0 => asteroid1_handle.0.clone(), 0 => asteroid1_handle.0.clone(),