use specs::{Component, VecStorage, NullStorage}; pub fn register(world: &mut specs::World) { world.register::(); world.register::(); world.register::(); world.register::(); world.register::(); world.register::(); world.register::(); } #[derive(Component, Debug)] #[storage(VecStorage)] pub struct Position { pub x: f32, pub y: f32, } impl Position { pub fn to_point(&self) -> ggez::nalgebra::Point2 { ggez::nalgebra::Point2::new(self.x * 3.0, self.y * 3.0) } } #[derive(Component, Debug)] #[storage(VecStorage)] pub struct Velocity { pub dx: f32, pub dy: f32, } impl Velocity { pub fn to_point(&self) -> ggez::nalgebra::Point2 { ggez::nalgebra::Point2::new(self.dx * 3.0, self.dy * 3.0) } } #[derive(Component, Debug)] #[storage(VecStorage)] pub struct Sprite { pub u: u8, pub v: u8, } impl Sprite { pub fn to_rect(&self) -> ggez::graphics::Rect { ggez::graphics::Rect { x: (1.0 / 32.0) * self.u as f32, y: (1.0 / 32.0) * self.v as f32, w: 1.0 / 32.0, h: 1.0 / 32.0, } } } #[derive(Component, Default, Debug)] #[storage(NullStorage)] pub struct Background; #[derive(Component, Default, Debug)] #[storage(NullStorage)] pub struct Foreground; #[derive(Component, Default, Debug)] #[storage(NullStorage)] pub struct Decoration; #[derive(Component, Default, Debug)] #[storage(NullStorage)] pub struct Movable;