move components to separate file

This commit is contained in:
Peter Hart 2020-03-28 21:12:18 -04:00
parent 217c4f7c3a
commit 419ab1ba35
2 changed files with 24 additions and 19 deletions

22
src/components.rs Normal file
View File

@ -0,0 +1,22 @@
use rltk::RGB;
use specs::prelude::*;
#[derive(Component)]
pub struct Position {
pub x: i32,
pub y: i32,
}
#[derive(Component)]
pub struct Renderable {
pub glyph: u8,
pub fg: RGB,
pub bg: RGB,
}
#[derive(Component)]
pub struct LeftMover {}
#[derive(Component, Debug)]
pub struct Player {}

View File

@ -5,33 +5,16 @@ mod rect;
pub use rect::*; pub use rect::*;
mod map; mod map;
pub use map::*; pub use map::*;
mod components;
pub use components::*;
#[macro_use] #[macro_use]
extern crate specs_derive; extern crate specs_derive;
#[derive(Component)]
pub struct Position {
x: i32,
y: i32,
}
#[derive(Component)]
pub struct Renderable {
glyph: u8,
fg: RGB,
bg: RGB,
}
pub struct State { pub struct State {
ecs: World, ecs: World,
} }
#[derive(Component)]
pub struct LeftMover {}
#[derive(Component, Debug)]
pub struct Player {}
fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) { fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) {
let mut positions = ecs.write_storage::<Position>(); let mut positions = ecs.write_storage::<Position>();
let mut players = ecs.write_storage::<Player>(); let mut players = ecs.write_storage::<Player>();