From b8be87868e498aa167862cf3c274d64190122faf Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 26 Oct 2021 14:38:30 -0400 Subject: [PATCH] Show first monsters --- src/main.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index a4971b3..ed20e80 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,9 +37,13 @@ impl GameState for State { let positions = self.ecs.read_storage::(); let renderables = self.ecs.read_storage::(); + let map = self.ecs.fetch::(); for (pos, render) in (&positions, &renderables).join() { - ctx.set(pos.x, pos.y, render.fg, render.bg, render.glyph); + 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); + } } } } @@ -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) }