diff --git a/src/actor.rs b/src/actor.rs index 9ace056..0fd7a52 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -503,7 +503,6 @@ fn handle_player_death( mut er_playerdies: EventReader, q_scenes: Query<(Entity, &SceneInstance), With>, q_noscenes: Query, Without)>, - ew_spawn: EventWriter, mut scene_spawner: ResMut, mut active_asteroids: ResMut, mut ew_effect: EventWriter, @@ -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 => { diff --git a/src/camera.rs b/src/camera.rs index 5b8d726..93aa253 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -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; }; diff --git a/src/menu.rs b/src/menu.rs index 12152ee..0afa997 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -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>, mut ew_sfx: EventWriter, mut ew_effect: EventWriter, + mut ew_respawn: EventWriter, mut settings: ResMut, ) { 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); } } } diff --git a/src/world.rs b/src/world.rs index 93cd310..6a2db0d 100644 --- a/src/world.rs +++ b/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::())); 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::(); + app.add_event::(); } } @@ -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::load_defs(ew_spawn); +}