summaryrefslogtreecommitdiff
path: root/src/systems/attacking.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/systems/attacking.rs')
-rw-r--r--src/systems/attacking.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/systems/attacking.rs b/src/systems/attacking.rs
index 6535a75..1f518cb 100644
--- a/src/systems/attacking.rs
+++ b/src/systems/attacking.rs
@@ -2,11 +2,12 @@
use specs::{
WriteStorage,
System,
+ Entities,
Join
};
use crate::{
- components::{Health, Attacked},
+ components::{Health, Attacked, Dying, Removed},
util
};
@@ -14,15 +15,22 @@ use crate::{
pub struct Attacking;
impl <'a> System<'a> for Attacking {
type SystemData = (
+ Entities<'a>,
WriteStorage<'a, Attacked>,
- WriteStorage<'a, Health>
+ WriteStorage<'a, Health>,
+ WriteStorage<'a, Dying>,
+ WriteStorage<'a, Removed>
);
- fn run(&mut self, (mut victims, mut healths): Self::SystemData) {
- for (health, attacked) in (&mut healths, &mut victims).join() {
+ fn run(&mut self, (entities, mut victims, mut healths, mut deads, mut removals): Self::SystemData) {
+ for (ent, health, attacked) in (&entities, &mut healths, &mut victims).join() {
for attack in attacked.attacks.drain(..) {
health.health -= attack.damage;
}
health.health = util::clamp(health.health, 0, health.maxhealth);
+ if health.health == 0 {
+ deads.insert(ent, Dying).unwrap();
+ removals.insert(ent, Removed).unwrap();
+ }
}
victims.clear();
}