move components to separate file
This commit is contained in:
parent
217c4f7c3a
commit
419ab1ba35
22
src/components.rs
Normal file
22
src/components.rs
Normal 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 {}
|
||||||
21
src/main.rs
21
src/main.rs
@ -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>();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user