From 86cdc6c567d0ca429d69bebbb2fb02f1d3754c8d Mon Sep 17 00:00:00 2001 From: troido Date: Sun, 23 Feb 2020 23:44:50 +0100 Subject: players can now attack other objects --- src/systems/attacking.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/systems/attacking.rs') 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(); } -- cgit