Show first monsters

This commit is contained in:
Timothy Warren 2021-10-26 14:38:30 -04:00
parent 1345248b15
commit b8be87868e

View File

@ -37,11 +37,15 @@ impl GameState for State {
let positions = self.ecs.read_storage::<Position>(); let positions = self.ecs.read_storage::<Position>();
let renderables = self.ecs.read_storage::<Renderable>(); let renderables = self.ecs.read_storage::<Renderable>();
let map = self.ecs.fetch::<Map>();
for (pos, render) in (&positions, &renderables).join() { 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); ctx.set(pos.x, pos.y, render.fg, render.bg, render.glyph);
} }
} }
}
} }
fn main() -> rltk::BError { fn main() -> rltk::BError {
@ -61,7 +65,23 @@ fn main() -> rltk::BError {
let map: Map = Map::new_map_rooms_and_corridors(); let map: Map = Map::new_map_rooms_and_corridors();
let (player_x, player_y) = map.rooms[0].center(); 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 gs.ecs
.create_entity() .create_entity()
@ -82,5 +102,7 @@ fn main() -> rltk::BError {
}) })
.build(); .build();
gs.ecs.insert(map);
rltk::main_loop(context, gs) rltk::main_loop(context, gs)
} }