diff options
author | Alexander Foremny <aforemny@posteo.de> | 2024-03-23 14:06:23 +0100 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2024-03-23 14:06:23 +0100 |
commit | 1219ed9a6c3b7cc978d70e0c62f96e09e8efe04f (patch) | |
tree | c34d3d7ad4528aed8d760bf350a6beda8f41e20f /src | |
parent | a061b97e5c541b2dc6c46184f78d5a18b35d9254 (diff) |
feat: respawn players
Diffstat (limited to 'src')
-rw-r--r-- | src/server.rs | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/server.rs b/src/server.rs index 413c7fd..d9eccb6 100644 --- a/src/server.rs +++ b/src/server.rs @@ -101,7 +101,8 @@ impl Plugin for ServerPlugin { (tower_ai, (minion_ai_attack, minion_ai_walk).chain()) .before(imperative_attack_approach), ) - .add_systems(FixedUpdate, minion_despawn) + .add_systems(FixedUpdate, despawn) + .add_systems(FixedUpdate, player_respawn) .add_systems(FixedUpdate, (nexus_tick, nexus_spawn_minions)) .add_systems( FixedUpdate, @@ -834,15 +835,27 @@ fn minion_ai_attack( } } -fn minion_despawn( - minions: Query<(Entity, &PlayerId, &Health), With<Minion>>, +fn despawn( + minions: Query<(Entity, &PlayerId, &Health), Without<Player>>, mut commands: Commands, mut entity_map: ResMut<EntityMap>, ) { - for (minion_entity, minion_player_id, minion_health) in minions.iter() { - if minion_health.health <= 0. { - commands.entity(minion_entity).despawn(); - entity_map.0.remove(&minion_player_id.0); + for (entity, player_id, health) in minions.iter() { + if health.health <= 0. { + commands.entity(entity).despawn(); + entity_map.0.remove(&player_id.0); + } + } +} + +fn player_respawn( + mut players: Query<(&mut Health, &mut PlayerPosition, &EffectiveStats), With<Player>>, +) { + for (mut health, mut player_position, effective_stats) in players.iter_mut() { + if health.health <= 0. { + health.health = effective_stats.0.max_health; + health.shield = 0.; + player_position.0 = Vec2::ZERO; } } } |