summaryrefslogtreecommitdiff
path: root/src/systems/attacking.rs
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-02-23 21:25:36 +0100
committertroido <troido@protonmail.com>2020-02-23 21:25:36 +0100
commit613952f918b8d72a3e397dc46be309b2320c6ad0 (patch)
tree2f34c1d8fb2aed771a5714a266845df095e5b438 /src/systems/attacking.rs
parent9a814769565ab36c227508c47792e112de338df1 (diff)
entities can be attacked
Diffstat (limited to 'src/systems/attacking.rs')
-rw-r--r--src/systems/attacking.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/systems/attacking.rs b/src/systems/attacking.rs
new file mode 100644
index 0000000..0fb5cf7
--- /dev/null
+++ b/src/systems/attacking.rs
@@ -0,0 +1,30 @@
+
+use specs::{
+ WriteStorage,
+ System,
+ Join
+};
+
+use crate::{
+ components::{Health, Attacked},
+ util
+};
+
+
+pub struct Attacking;
+impl <'a> System<'a> for Attacking {
+ type SystemData = (
+ WriteStorage<'a, Attacked>,
+ WriteStorage<'a, Health>
+ );
+ fn run(&mut self, (mut victims, mut healths): Self::SystemData) {
+
+ for (health, attacked) in (&mut healths, &mut victims).join() {
+ for attack in attacked.attacks.drain(..) {
+ health.health -= attack.damage;
+ }
+ health.health = util::clamp(health.health, 0, health.maxhealth);
+ }
+ }
+}
+