123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- use specs::{Component, VecStorage, NullStorage};
- pub fn register(world: &mut specs::World) {
- world.register::<Position>();
- world.register::<Velocity>();
- world.register::<Sprite>();
- world.register::<Background>();
- world.register::<Foreground>();
- world.register::<Decoration>();
- world.register::<Movable>();
- }
- #[derive(Component, Debug)]
- #[storage(VecStorage)]
- pub struct Position {
- pub x: f32,
- pub y: f32,
- }
- impl Position {
- pub fn to_point(&self) -> ggez::nalgebra::Point2<f32> {
- 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<f32> {
- 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;
|