respawn the world on death only after death screen closes
This commit is contained in:
parent
182659eff0
commit
69381db524
|
@ -503,7 +503,6 @@ fn handle_player_death(
|
|||
mut er_playerdies: EventReader<PlayerDiesEvent>,
|
||||
q_scenes: Query<(Entity, &SceneInstance), With<world::DespawnOnPlayerDeath>>,
|
||||
q_noscenes: Query<Entity, (With<world::DespawnOnPlayerDeath>, Without<SceneInstance>)>,
|
||||
ew_spawn: EventWriter<commands::SpawnEvent>,
|
||||
mut scene_spawner: ResMut<SceneSpawner>,
|
||||
mut active_asteroids: ResMut<world::ActiveAsteroids>,
|
||||
mut ew_effect: EventWriter<visual::SpawnEffectEvent>,
|
||||
|
@ -525,7 +524,6 @@ fn handle_player_death(
|
|||
scene_spawner.despawn_instance(**sceneinstance);
|
||||
}
|
||||
log.clear();
|
||||
//cmd.run_system(commands::load_defs); // why is it so complicated to get SystemId?
|
||||
|
||||
match death.0 {
|
||||
DamageType::Mental => {
|
||||
|
|
|
@ -716,11 +716,9 @@ pub fn position_to_transform(
|
|||
) {
|
||||
let center: DVec3 = if settings.map_active {
|
||||
mapcam.center
|
||||
}
|
||||
else if let Ok(player_pos) = q_player.get_single() {
|
||||
} else if let Ok(player_pos) = q_player.get_single() {
|
||||
**player_pos
|
||||
} else {
|
||||
error!("Can't find player's position");
|
||||
return;
|
||||
};
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
// This plugin manages game menus and the player death screen
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::{audio, hud, visual};
|
||||
use crate::{audio, hud, visual, world};
|
||||
use bevy::prelude::*;
|
||||
|
||||
pub struct MenuPlugin;
|
||||
|
@ -110,6 +110,7 @@ pub fn show_deathscreen(
|
|||
mut q_text: Query<&mut Text, With<DeathText>>,
|
||||
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
|
||||
mut ew_effect: EventWriter<visual::SpawnEffectEvent>,
|
||||
mut ew_respawn: EventWriter<world::RespawnEvent>,
|
||||
mut settings: ResMut<Settings>,
|
||||
) {
|
||||
for event in er_deathscreen.read() {
|
||||
|
@ -126,6 +127,7 @@ pub fn show_deathscreen(
|
|||
} else {
|
||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::WakeUp));
|
||||
ew_effect.send(visual::SpawnEffectEvent { class: visual::Effects::FadeIn(Color::BLACK), duration: 0.3 });
|
||||
ew_respawn.send(world::RespawnEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
12
src/world.rs
12
src/world.rs
|
@ -11,7 +11,7 @@
|
|||
// This module populates the world with stars and asteroids.
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::{actor, hud, load, nature};
|
||||
use crate::{actor, commands, hud, load, nature};
|
||||
use bevy::prelude::*;
|
||||
use bevy::math::{DVec3, I64Vec3};
|
||||
use bevy::scene::{InstanceId, SceneInstance};
|
||||
|
@ -40,6 +40,7 @@ impl Plugin for WorldPlugin {
|
|||
app.add_systems(Startup, setup);
|
||||
app.add_systems(PostUpdate, handle_despawn);
|
||||
app.add_systems(Update, spawn_despawn_asteroids);
|
||||
app.add_systems(Update, handle_respawn.run_if(on_event::<RespawnEvent>()));
|
||||
app.add_plugins(PhysicsPlugins::default());
|
||||
//app.add_plugins(PhysicsDebugPlugin::default());
|
||||
app.insert_resource(Gravity(DVec3::splat(0.0)));
|
||||
|
@ -47,6 +48,7 @@ impl Plugin for WorldPlugin {
|
|||
Timer::from_seconds(ASTEROID_UPDATE_INTERVAL, TimerMode::Repeating)));
|
||||
app.insert_resource(ActiveAsteroids(HashMap::new()));
|
||||
app.add_event::<DespawnEvent>();
|
||||
app.add_event::<RespawnEvent>();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,6 +58,8 @@ impl Plugin for WorldPlugin {
|
|||
#[derive(Component)] struct Asteroid;
|
||||
#[derive(Component)] pub struct DespawnOnPlayerDeath;
|
||||
|
||||
#[derive(Event)] pub struct RespawnEvent;
|
||||
|
||||
pub struct AsteroidData {
|
||||
entity: Entity,
|
||||
//viewdistance: f64,
|
||||
|
@ -345,3 +349,9 @@ fn handle_despawn(
|
|||
db.0.remove(&despawn.origin);
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_respawn(
|
||||
ew_spawn: EventWriter<commands::SpawnEvent>,
|
||||
) {
|
||||
commands::load_defs(ew_spawn);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue