Add first entity

This commit is contained in:
Timothy Warren 2021-10-21 12:54:39 -04:00
parent 8395c5ad61
commit 6f65bf2420

View File

@ -1,6 +1,24 @@
use rltk::{Rltk, GameState};
use rltk::{GameState, Rltk, VirtualKeyCode, RGB};
use specs::prelude::*;
use specs_derive::Component;
use std::cmp::{max, min};
struct State {}
#[derive(Component)]
struct Position {
x: i32,
y: i32,
}
#[derive(Component)]
struct Renderable {
glyph: rltk::FontCharType,
fg: RGB,
bg: RGB,
}
struct State {
ecs: World,
}
impl GameState for State {
fn tick(&mut self, ctx: &mut Rltk) {
@ -16,7 +34,20 @@ fn main() -> rltk::BError {
.with_title("Roguelike Tutorial")
.build()?;
let gs = State {};
let mut gs = State { ecs: World::new() };
gs.ecs.register::<Position>();
gs.ecs.register::<Renderable>();
gs.ecs
.create_entity()
.with(Position { x: 40, y: 25 })
.with(Renderable {
glyph: rltk::to_cp437('@'),
fg: RGB::named(rltk::YELLOW),
bg: RGB::named(rltk::BLACK),
})
.build();
rltk::main_loop(context, gs)
}
}