diff options
| author | troido <troido@protonmail.com> | 2020-02-28 12:40:52 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-02-28 12:40:52 +0100 |
| commit | 40e4e9e7a7e2c59a5659d8d4bd2ecfafed967299 (patch) | |
| tree | fa2c2bb9b293781a871ca64915b5c0149e36fd6c /src/systems/updatecooldowns.rs | |
| parent | 481e03e04b055cebaf230b3a3cdce3446418c68c (diff) | |
added cooldowns for moving and fighting
Diffstat (limited to 'src/systems/updatecooldowns.rs')
| -rw-r--r-- | src/systems/updatecooldowns.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/systems/updatecooldowns.rs b/src/systems/updatecooldowns.rs new file mode 100644 index 0000000..73ca770 --- /dev/null +++ b/src/systems/updatecooldowns.rs @@ -0,0 +1,33 @@ + +use specs::{ + WriteStorage, + Entities, + System, + Join +}; + +use crate::components::ControlCooldown; + + +pub struct UpdateCooldowns; +impl <'a> System<'a> for UpdateCooldowns { + type SystemData = ( + Entities<'a>, + WriteStorage<'a, ControlCooldown> + ); + fn run(&mut self, (entities, mut cooldowns): Self::SystemData) { + let mut to_remove = Vec::new(); + for (entity, cooldown) in (&entities, &mut cooldowns).join() { + if cooldown.amount > 0 { + cooldown.amount -= 1; + } + if cooldown.amount <= 0 { + to_remove.push(entity); + } + } + for entity in to_remove { + cooldowns.remove(entity); + } + } +} + |
