From d84906ec92e45ed2cf2611c2f646d72ef5f1bb64 Mon Sep 17 00:00:00 2001 From: Iago Garrido Date: Tue, 12 Nov 2019 14:28:58 +0100 Subject: add state --- src/world.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'src/world.rs') diff --git a/src/world.rs b/src/world.rs index 24a4c31..4f2a645 100644 --- a/src/world.rs +++ b/src/world.rs @@ -1,9 +1,10 @@ use rand::Rng; +use pancurses::{Window}; pub type Point = (usize, usize); #[derive(Clone)] -pub enum TileType { +enum TileType { Empty, Wall, Floor, @@ -226,6 +227,38 @@ impl Dungeon { levels: vec![] } } + + pub fn debug_levels(&self) { + for l in &self.levels { + Dungeon::debug_level(l); + } + } + + fn draw_block(window: &Window, block: &TileType) { + window.printw(Dungeon::tile_to_str(block)); + } + + fn debug_level(level: &Level) { + let grid = level.to_tilegrid().unwrap(); + + for line in grid.raw_data().iter() { + for block in line.iter() { + print!("{}", Dungeon::tile_to_str(block)); + } + print!("\n"); + } + } + + fn tile_to_str(tile: &TileType) -> &str { + match tile { + TileType::Floor => ".", + TileType::Wall => "#", + TileType::Empty => " ", + TileType::StairsDown => ">", + TileType::StairsUp => "<", + TileType::Character => "@", + } + } } impl Generable for Dungeon { @@ -251,7 +284,7 @@ impl Level { } } - pub fn to_tilegrid(&self) -> Result { + fn to_tilegrid(&self) -> Result { let mut grid = TileGrid::new(self.xsize, self.ysize); for room in &self.rooms { @@ -272,6 +305,17 @@ impl Level { return (0,0) } + pub fn render(&self, window: &Window) { + let grid = self.to_tilegrid().unwrap(); + + for (linenum, line) in grid.raw_data().iter().enumerate() { + for block in line.iter() { + Dungeon::draw_block(&window, &block); + } + window.mv(linenum as i32, 0); + } + } + fn overlaps(&self, start: Point, width: usize, height: usize, padding: usize) -> bool { for room in &self.rooms { if room.start.0 < start.0 + width + padding && -- cgit v1.2.3