summaryrefslogtreecommitdiff
path: root/src/systems/updatecooldowns.rs
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-02-28 12:40:52 +0100
committertroido <troido@protonmail.com>2020-02-28 12:40:52 +0100
commit40e4e9e7a7e2c59a5659d8d4bd2ecfafed967299 (patch)
treefa2c2bb9b293781a871ca64915b5c0149e36fd6c /src/systems/updatecooldowns.rs
parent481e03e04b055cebaf230b3a3cdce3446418c68c (diff)
added cooldowns for moving and fighting
Diffstat (limited to 'src/systems/updatecooldowns.rs')
-rw-r--r--src/systems/updatecooldowns.rs33
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);
+ }
+ }
+}
+