|
@@ -3,29 +3,35 @@ use rand::Rng;
|
|
|
use specs::prelude::*;
|
|
|
|
|
|
#[derive(PartialEq, Clone, Copy, Debug)]
|
|
|
-pub enum TileType {
|
|
|
- Wall,
|
|
|
- Floor,
|
|
|
+pub struct Cell {
|
|
|
+ pub tile: TileType,
|
|
|
+ pub seen: bool,
|
|
|
}
|
|
|
|
|
|
-impl TileType {
|
|
|
+impl Cell {
|
|
|
pub fn glyph(&self) -> carpet::CP437 {
|
|
|
- match self {
|
|
|
+ match self.tile {
|
|
|
TileType::Wall => carpet::CP437::from_char('#'),
|
|
|
TileType::Floor => carpet::CP437::from_u8(0),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
pub fn blocks_view(&self) -> bool {
|
|
|
- match self {
|
|
|
+ match self.tile {
|
|
|
TileType::Wall => true,
|
|
|
TileType::Floor => false,
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#[derive(PartialEq, Clone, Copy, Debug)]
|
|
|
+pub enum TileType {
|
|
|
+ Wall,
|
|
|
+ Floor,
|
|
|
+}
|
|
|
+
|
|
|
pub struct Map {
|
|
|
- pub tiles: carpet::Board<TileType>,
|
|
|
+ pub tiles: carpet::Board<Cell>,
|
|
|
pub rooms: Vec<carpet::Rect>,
|
|
|
}
|
|
|
|
|
@@ -33,7 +39,7 @@ impl Map {
|
|
|
pub fn new() -> Map {
|
|
|
let mut rng = rand::thread_rng();
|
|
|
let mut map = Map {
|
|
|
- tiles: carpet::Board::new_with_default(80, 50, TileType::Wall),
|
|
|
+ tiles: carpet::Board::new_with_default(80, 50, Cell { tile: TileType::Wall, seen: false }),
|
|
|
rooms: Vec::new(),
|
|
|
};
|
|
|
|
|
@@ -75,17 +81,20 @@ impl Map {
|
|
|
.window_iter_mut(rect)
|
|
|
.unwrap_or_else(|| panic!("Rect {:?} of map bounds", rect));
|
|
|
for (_, _, t) in iter {
|
|
|
- *t = TileType::Floor;
|
|
|
+ t.tile = TileType::Floor;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
pub fn passable(&self, (x, y): (usize, usize)) -> bool {
|
|
|
- Some(&TileType::Floor) == self.tiles.get(x, y)
|
|
|
+ if let Some(cell) = self.tiles.get(x, y) {
|
|
|
+ return cell.tile == TileType::Floor;
|
|
|
+ }
|
|
|
+ false
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#[derive(Component)]
|
|
|
pub struct Viewshed {
|
|
|
- pub vs: carpet::Viewshed<TileType>,
|
|
|
+ pub vs: carpet::Viewshed<Cell>,
|
|
|
pub dirty: bool,
|
|
|
}
|