Add first entity
This commit is contained in:
parent
8395c5ad61
commit
6f65bf2420
39
src/main.rs
39
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 {
|
impl GameState for State {
|
||||||
fn tick(&mut self, ctx: &mut Rltk) {
|
fn tick(&mut self, ctx: &mut Rltk) {
|
||||||
@ -16,7 +34,20 @@ fn main() -> rltk::BError {
|
|||||||
.with_title("Roguelike Tutorial")
|
.with_title("Roguelike Tutorial")
|
||||||
.build()?;
|
.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)
|
rltk::main_loop(context, gs)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user