use enum_dispatch::enum_dispatch; use crate::{ scaler::{Pos, Velo}, system::EntityContainer, }; /// 一个实体的能力 #[enum_dispatch] pub trait Ability { fn tick(&mut self, sys: &EntityContainer) -> Self; } /// 各种能力 /// 所有的能力的枚举,用以静态分发 #[enum_dispatch(Ability)] #[derive(Clone, Copy)] pub enum Abilities { Movement, } /// 移动能力 #[derive(Clone, Copy)] pub struct Movement(pub Pos, pub Velo); impl Ability for Movement { fn tick(&mut self, _sys: &EntityContainer) -> Self { self.0 = self.0 + self.1; *self } } /// 碰撞能力 #[derive(Clone, Copy)] pub struct Vertical (pub Pos, pub Velo);