Show first monsters
This commit is contained in:
parent
1345248b15
commit
b8be87868e
24
src/main.rs
24
src/main.rs
@ -37,12 +37,16 @@ impl GameState for State {
|
||||
|
||||
let positions = self.ecs.read_storage::<Position>();
|
||||
let renderables = self.ecs.read_storage::<Renderable>();
|
||||
let map = self.ecs.fetch::<Map>();
|
||||
|
||||
for (pos, render) in (&positions, &renderables).join() {
|
||||
let idx = map.xy_idx(pos.x, pos.y);
|
||||
if map.visible_tiles[idx] {
|
||||
ctx.set(pos.x, pos.y, render.fg, render.bg, render.glyph);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> rltk::BError {
|
||||
use rltk::RltkBuilder;
|
||||
@ -61,7 +65,23 @@ fn main() -> rltk::BError {
|
||||
let map: Map = Map::new_map_rooms_and_corridors();
|
||||
let (player_x, player_y) = map.rooms[0].center();
|
||||
|
||||
gs.ecs.insert(map);
|
||||
for room in map.rooms.iter().skip(1) {
|
||||
let (x, y) = room.center();
|
||||
gs.ecs
|
||||
.create_entity()
|
||||
.with(Position { x, y })
|
||||
.with(Renderable {
|
||||
glyph: rltk::to_cp437('g'),
|
||||
fg: RGB::named(rltk::RED),
|
||||
bg: RGB::named(rltk::BLACK),
|
||||
})
|
||||
.with(Viewshed {
|
||||
visible_tiles: Vec::new(),
|
||||
range: 8,
|
||||
dirty: true,
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
gs.ecs
|
||||
.create_entity()
|
||||
@ -82,5 +102,7 @@ fn main() -> rltk::BError {
|
||||
})
|
||||
.build();
|
||||
|
||||
gs.ecs.insert(map);
|
||||
|
||||
rltk::main_loop(context, gs)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user