Start on chapter 3

This commit is contained in:
Timothy Warren 2020-07-24 14:55:49 -04:00
parent 0d31199910
commit 766c1a0105
2 changed files with 22 additions and 4 deletions

View File

@ -1,6 +1,16 @@
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)]
#[storage(VecStorage)]
pub struct Position {
@ -13,6 +23,10 @@ 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)]
@ -31,11 +45,15 @@ pub struct Player {}
#[derive(Component)]
#[storage(VecStorage)]
pub struct Box {}
pub struct Box {
pub color: BoxColor,
}
#[derive(Component)]
#[storage(VecStorage)]
pub struct BoxSpot {}
pub struct BoxSpot {
pub color: BoxColor,
}
#[derive(Component, Default)]
#[storage(NullStorage)]

View File

@ -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> {
return world
.create_entity()
.with(Position { z, ..position })
.with(position.with_z(z))
.with(Renderable { path: sprite_path.to_string() });
}