visibile area highlighting

This commit is contained in:
Peter Hart 2020-03-29 20:36:52 -04:00
parent bafe3fcbc9
commit 222e2e5e74
3 changed files with 19 additions and 25 deletions

View File

@ -85,26 +85,22 @@ pub fn draw_map(ecs: &World, ctx: &mut Rltk) {
for (idx, tile) in map.tiles.iter().enumerate() { for (idx, tile) in map.tiles.iter().enumerate() {
// Render a tile depending upon the tile type, if revealed // Render a tile depending upon the tile type, if revealed
if map.revealed_tiles[idx] { if map.revealed_tiles[idx] {
let glyph;
let mut fg;
match tile { match tile {
TileType::Floor => { TileType::Floor => {
ctx.set( glyph = rltk::to_cp437('.');
x, fg = RGB::from_f32(0.5, 0.5, 0.5);
y,
RGB::from_f32(0.5, 0.5, 0.5),
RGB::from_f32(0., 0., 0.),
rltk::to_cp437('.'),
);
} }
TileType::Wall => { TileType::Wall => {
ctx.set( glyph = rltk::to_cp437('#');
x, fg = RGB::from_f32(0.0, 1.0, 0.0);
y,
RGB::from_f32(0.0, 1.0, 0.0),
RGB::from_f32(0., 0., 0.),
rltk::to_cp437('#'),
);
} }
} }
if !map.visible_tiles[idx] {
fg = fg.to_greyscale()
}
ctx.set(x, y, fg, RGB::from_f32(0., 0., 0.), glyph);
} }
// Move the coordinates // Move the coordinates

View File

@ -14,6 +14,7 @@ pub struct Map {
pub width: i32, pub width: i32,
pub height: i32, pub height: i32,
pub revealed_tiles: Vec<bool>, pub revealed_tiles: Vec<bool>,
pub visible_tiles: Vec<bool>,
} }
impl Map { impl Map {
@ -55,6 +56,7 @@ impl Map {
width: 80, width: 80,
height: 50, height: 50,
revealed_tiles: vec![false; 80 * 50], revealed_tiles: vec![false; 80 * 50],
visible_tiles: vec![false; 80 * 50],
}; };
const MAX_ROOMS: i32 = 30; const MAX_ROOMS: i32 = 30;
@ -82,18 +84,10 @@ impl Map {
let r2_center = map.rooms[map.rooms.len() - 1].center(); let r2_center = map.rooms[map.rooms.len() - 1].center();
if rng.range(0, 2) == 1 { if rng.range(0, 2) == 1 {
map.apply_horizontal_tunnel(r1_center.0, r2_center.0, r1_center.1); map.apply_horizontal_tunnel(r1_center.0, r2_center.0, r1_center.1);
map.apply_vertical_tunnel( map.apply_vertical_tunnel(r2_center.0, r1_center.1, r2_center.1);
r2_center.0,
r1_center.1,
r2_center.1,
);
} else { } else {
map.apply_vertical_tunnel(r1_center.0, r1_center.1, r2_center.1); map.apply_vertical_tunnel(r1_center.0, r1_center.1, r2_center.1);
map.apply_horizontal_tunnel( map.apply_horizontal_tunnel(r1_center.0, r2_center.0, r2_center.1);
r1_center.0,
r2_center.0,
r2_center.1,
);
} }
} }
map.rooms.push(new_room); map.rooms.push(new_room);

View File

@ -27,10 +27,14 @@ impl<'a> System<'a> for VisibilitySystem {
// If this is the player, reveal what they can see // If this is the player, reveal what they can see
let p: Option<&Player> = player.get(ent); 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() { for vis in viewshed.visible_tiles.iter() {
let idx = map.xy_idx(vis.x, vis.y); let idx = map.xy_idx(vis.x, vis.y);
map.revealed_tiles[idx] = true; map.revealed_tiles[idx] = true;
map.visible_tiles[idx] = true;
} }
} }
} }