Start on chapter 3
This commit is contained in:
parent
0d31199910
commit
766c1a0105
@ -1,6 +1,16 @@
|
|||||||
use specs::{Component, NullStorage, VecStorage, World, WorldExt};
|
use specs::{Component, NullStorage, VecStorage, World, WorldExt};
|
||||||
|
|
||||||
// Components
|
pub enum BoxColor {
|
||||||
|
Red,
|
||||||
|
Blue,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for BoxColor {
|
||||||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Component, Clone, Copy)]
|
#[derive(Debug, Component, Clone, Copy)]
|
||||||
#[storage(VecStorage)]
|
#[storage(VecStorage)]
|
||||||
pub struct Position {
|
pub struct Position {
|
||||||
@ -13,6 +23,10 @@ impl Position {
|
|||||||
pub fn new(x: u8, y: u8) -> Self {
|
pub fn new(x: u8, y: u8) -> Self {
|
||||||
Position { x, y, z: 0 }
|
Position { x, y, z: 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_z(self, z: u8) -> Self {
|
||||||
|
Position { z, ..self }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
@ -31,11 +45,15 @@ pub struct Player {}
|
|||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
#[storage(VecStorage)]
|
#[storage(VecStorage)]
|
||||||
pub struct Box {}
|
pub struct Box {
|
||||||
|
pub color: BoxColor,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
#[storage(VecStorage)]
|
#[storage(VecStorage)]
|
||||||
pub struct BoxSpot {}
|
pub struct BoxSpot {
|
||||||
|
pub color: BoxColor,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Component, Default)]
|
#[derive(Component, Default)]
|
||||||
#[storage(NullStorage)]
|
#[storage(NullStorage)]
|
||||||
|
@ -5,7 +5,7 @@ use specs::{Builder, World, WorldExt, EntityBuilder};
|
|||||||
fn common_entity<'w>(world: &'w mut World, position: Position, z: u8, sprite_path: &str) -> EntityBuilder<'w> {
|
fn common_entity<'w>(world: &'w mut World, position: Position, z: u8, sprite_path: &str) -> EntityBuilder<'w> {
|
||||||
return world
|
return world
|
||||||
.create_entity()
|
.create_entity()
|
||||||
.with(Position { z, ..position })
|
.with(position.with_z(z))
|
||||||
.with(Renderable { path: sprite_path.to_string() });
|
.with(Renderable { path: sprite_path.to_string() });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user