roguelike-game/src/main.rs

54 lines
1.0 KiB
Rust
Raw Normal View History

2021-10-21 12:54:39 -04:00
use rltk::{GameState, Rltk, VirtualKeyCode, RGB};
use specs::prelude::*;
use specs_derive::Component;
use std::cmp::{max, min};
2021-10-20 12:01:15 -04:00
2021-10-21 12:54:39 -04:00
#[derive(Component)]
struct Position {
x: i32,
y: i32,
}
#[derive(Component)]
struct Renderable {
glyph: rltk::FontCharType,
fg: RGB,
bg: RGB,
}
struct State {
ecs: World,
}
2021-10-20 12:01:15 -04:00
impl GameState for State {
fn tick(&mut self, ctx: &mut Rltk) {
ctx.cls();
ctx.print(1, 1, "Hello Rust World");
}
}
fn main() -> rltk::BError {
use rltk::RltkBuilder;
let context = RltkBuilder::simple80x50()
.with_title("Roguelike Tutorial")
.build()?;
2021-10-21 12:54:39 -04:00
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();
2021-10-20 12:01:15 -04:00
rltk::main_loop(context, gs)
2021-10-21 12:54:39 -04:00
}