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/components/mod.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/components/mod.rs') diff --git a/src/components/mod.rs b/src/components/mod.rs index 0c258dc..330bc67 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -9,7 +9,9 @@ use specs::{ HashMapStorage, FlaggedStorage, NullStorage, - Component + Component, + Entity, + WriteStorage }; use crate::{ @@ -121,14 +123,33 @@ pub struct Attacked { pub attacks: Vec } +pub fn add_attack(attacked: &mut WriteStorage , ent: Entity, attack: Attack) { + attacked + .entry(ent) + .unwrap() + .or_insert_with(Attacked::default) + .attacks + .push(attack); +} + #[derive(Default, Component, Debug, Clone)] #[storage(NullStorage)] pub struct Entered; +#[derive(Default, Component, Debug, Clone)] +#[storage(NullStorage)] +pub struct Dying; + +#[derive(Component, Debug, Clone)] +#[storage(HashMapStorage)] +pub struct Trap { + pub attack: Attack +} + #[derive(Component, Debug, Clone)] #[storage(HashMapStorage)] -pub struct Trap{ +pub struct Fighter { pub attack: Attack } -- cgit