visibile area highlighting
This commit is contained in:
parent
bafe3fcbc9
commit
222e2e5e74
24
src/main.rs
24
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
|
||||
|
||||
14
src/map.rs
14
src/map.rs
@ -14,6 +14,7 @@ pub struct Map {
|
||||
pub width: i32,
|
||||
pub height: i32,
|
||||
pub revealed_tiles: Vec<bool>,
|
||||
pub visible_tiles: Vec<bool>,
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user