diff --git a/src/main.rs b/src/main.rs index c15774e..e28ea87 100644 --- a/src/main.rs +++ b/src/main.rs @@ -85,26 +85,22 @@ pub fn draw_map(ecs: &World, ctx: &mut Rltk) { for (idx, tile) in map.tiles.iter().enumerate() { // Render a tile depending upon the tile type, if revealed if map.revealed_tiles[idx] { + let glyph; + let mut fg; match tile { TileType::Floor => { - ctx.set( - x, - y, - RGB::from_f32(0.5, 0.5, 0.5), - RGB::from_f32(0., 0., 0.), - rltk::to_cp437('.'), - ); + glyph = rltk::to_cp437('.'); + fg = RGB::from_f32(0.5, 0.5, 0.5); } TileType::Wall => { - ctx.set( - x, - y, - RGB::from_f32(0.0, 1.0, 0.0), - RGB::from_f32(0., 0., 0.), - rltk::to_cp437('#'), - ); + glyph = rltk::to_cp437('#'); + fg = RGB::from_f32(0.0, 1.0, 0.0); } } + if !map.visible_tiles[idx] { + fg = fg.to_greyscale() + } + ctx.set(x, y, fg, RGB::from_f32(0., 0., 0.), glyph); } // Move the coordinates diff --git a/src/map.rs b/src/map.rs index 5f92245..75d19d1 100644 --- a/src/map.rs +++ b/src/map.rs @@ -14,6 +14,7 @@ pub struct Map { pub width: i32, pub height: i32, pub revealed_tiles: Vec, + pub visible_tiles: Vec, } impl Map { @@ -55,6 +56,7 @@ impl Map { width: 80, height: 50, revealed_tiles: vec![false; 80 * 50], + visible_tiles: vec![false; 80 * 50], }; const MAX_ROOMS: i32 = 30; @@ -82,18 +84,10 @@ impl Map { let r2_center = map.rooms[map.rooms.len() - 1].center(); if rng.range(0, 2) == 1 { map.apply_horizontal_tunnel(r1_center.0, r2_center.0, r1_center.1); - map.apply_vertical_tunnel( - r2_center.0, - r1_center.1, - r2_center.1, - ); + map.apply_vertical_tunnel(r2_center.0, r1_center.1, r2_center.1); } else { map.apply_vertical_tunnel(r1_center.0, r1_center.1, r2_center.1); - map.apply_horizontal_tunnel( - r1_center.0, - r2_center.0, - r2_center.1, - ); + map.apply_horizontal_tunnel(r1_center.0, r2_center.0, r2_center.1); } } map.rooms.push(new_room); diff --git a/src/visibility_system.rs b/src/visibility_system.rs index 47bfc68..8dcfd7e 100644 --- a/src/visibility_system.rs +++ b/src/visibility_system.rs @@ -27,10 +27,14 @@ impl<'a> System<'a> for VisibilitySystem { // If this is the player, reveal what they can see let p: Option<&Player> = player.get(ent); - if let Some(p) = p { + if let Some(_) = p { + for t in map.visible_tiles.iter_mut() { + *t = false + } for vis in viewshed.visible_tiles.iter() { let idx = map.xy_idx(vis.x, vis.y); map.revealed_tiles[idx] = true; + map.visible_tiles[idx] = true; } } }