From 40e4e9e7a7e2c59a5659d8d4bd2ecfafed967299 Mon Sep 17 00:00:00 2001 From: troido Date: Fri, 28 Feb 2020 12:40:52 +0100 Subject: added cooldowns for moving and fighting --- src/systems/updatecooldowns.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/systems/updatecooldowns.rs (limited to 'src/systems/updatecooldowns.rs') 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); + } + } +} + -- cgit