From 6f65bf2420cc46c7d33f1ed4aa705968242ed456 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 21 Oct 2021 12:54:39 -0400 Subject: [PATCH] Add first entity --- src/main.rs | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 65ca8cd..dc20cc0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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::(); + gs.ecs.register::(); + + 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) -} \ No newline at end of file +}