handling visibility, also fixed corridor issue

This commit is contained in:
2020-03-29 15:48:52 -04:00
parent 6a5514d6bb
commit bafe3fcbc9
3 changed files with 89 additions and 49 deletions

View File

@@ -67,8 +67,7 @@ impl GameState for State {
ctx.cls();
self.run_systems();
player_input(self, ctx);
let map = self.ecs.fetch::<Map>();
map.draw_map(ctx);
draw_map(&self.ecs, ctx);
let positions = self.ecs.read_storage::<Position>();
let renderables = self.ecs.read_storage::<Renderable>();
@@ -78,6 +77,45 @@ impl GameState for State {
}
}
pub fn draw_map(ecs: &World, ctx: &mut Rltk) {
let map = ecs.fetch::<Map>();
let mut y = 0;
let mut x = 0;
for (idx, tile) in map.tiles.iter().enumerate() {
// Render a tile depending upon the tile type, if revealed
if map.revealed_tiles[idx] {
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('.'),
);
}
TileType::Wall => {
ctx.set(
x,
y,
RGB::from_f32(0.0, 1.0, 0.0),
RGB::from_f32(0., 0., 0.),
rltk::to_cp437('#'),
);
}
}
}
// Move the coordinates
x += 1;
if x >= map.width {
x = 0;
y += 1;
}
}
}
fn main() {
use rltk::RltkBuilder;
let context = RltkBuilder::simple80x50()