rust-sokoban/src/components.rs

76 lines
1.4 KiB
Rust

use specs::{Component, NullStorage, VecStorage, World, WorldExt};
pub enum BoxColor {
Red,
Blue,
}
impl Display for BoxColor {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
}
}
#[derive(Debug, Component, Clone, Copy)]
#[storage(VecStorage)]
pub struct Position {
pub x: u8,
pub y: u8,
pub z: u8,
}
impl Position {
pub fn new(x: u8, y: u8) -> Self {
Position { x, y, z: 0 }
}
pub fn with_z(self, z: u8) -> Self {
Position { z, ..self }
}
}
#[derive(Component)]
#[storage(VecStorage)]
pub struct Renderable {
pub path: String,
}
#[derive(Component)]
#[storage(VecStorage)]
pub struct Wall {}
#[derive(Component)]
#[storage(VecStorage)]
pub struct Player {}
#[derive(Component)]
#[storage(VecStorage)]
pub struct Box {
pub color: BoxColor,
}
#[derive(Component)]
#[storage(VecStorage)]
pub struct BoxSpot {
pub color: BoxColor,
}
#[derive(Component, Default)]
#[storage(NullStorage)]
pub struct Movable;
#[derive(Component, Default)]
#[storage(NullStorage)]
pub struct Immovable;
pub fn register_components(world: &mut World) {
world.register::<Position>();
world.register::<Renderable>();
world.register::<Player>();
world.register::<Wall>();
world.register::<Box>();
world.register::<BoxSpot>();
world.register::<Movable>();
world.register::<Immovable>();
}