diff options
| author | alf9310 <alf9310@rit.edu> | 2025-11-06 12:20:57 -0500 |
|---|---|---|
| committer | alf9310 <alf9310@rit.edu> | 2025-11-06 12:20:57 -0500 |
| commit | 763b047c92a5d5340bad38506862ad6c87ecdbe9 (patch) | |
| tree | 68b391d3745458005eade3c07ac9e41655376d5c /dungeon/src | |
| parent | Moved most of the movement stuff to entity. (diff) | |
| download | DungeonCrawl-763b047c92a5d5340bad38506862ad6c87ecdbe9.tar.gz DungeonCrawl-763b047c92a5d5340bad38506862ad6c87ecdbe9.tar.bz2 DungeonCrawl-763b047c92a5d5340bad38506862ad6c87ecdbe9.zip | |
Light bsp refactoring
Diffstat (limited to 'dungeon/src')
| -rw-r--r-- | dungeon/src/bsp.rs | 7 | ||||
| -rw-r--r-- | dungeon/src/lib.rs | 14 | ||||
| -rw-r--r-- | dungeon/src/map.rs | 2 |
3 files changed, 13 insertions, 10 deletions
diff --git a/dungeon/src/bsp.rs b/dungeon/src/bsp.rs index be0f282..4c72389 100644 --- a/dungeon/src/bsp.rs +++ b/dungeon/src/bsp.rs @@ -397,10 +397,11 @@ pub fn generate(seed: u64) -> (Box<[Tile; TILE_COUNT]>, Pos) { (tiles_box, player_start) } -/// Tests +/// BSP Unit Tests #[cfg(test)] mod tests { use super::*; + use crate::map::MAP_SIZE; #[test] fn test_rect_center() { @@ -469,7 +470,7 @@ mod tests { let air_count = tiles.iter().filter(|&&t| t == Tile::Air).count(); assert!(air_count > 0); // Check that player_start is within bounds - assert!(player_start.xy().0 < MAP_SIZE_USIZE as u16); - assert!(player_start.xy().1 < MAP_SIZE_USIZE as u16); + assert!(player_start.xy().0 < MAP_SIZE); + assert!(player_start.xy().1 < MAP_SIZE); } } diff --git a/dungeon/src/lib.rs b/dungeon/src/lib.rs index 8119119..ee61632 100644 --- a/dungeon/src/lib.rs +++ b/dungeon/src/lib.rs @@ -1,11 +1,11 @@ //! The `dungon` crate contains the core functionality for //! interacting with a `Dungeon` and its components. -mod bsp; -mod enemy; -mod entity; -mod map; -mod pos; +pub mod bsp; +pub mod enemy; +pub mod entity; +pub mod map; +pub mod pos; pub use bsp::*; pub use entity::*; @@ -70,9 +70,11 @@ impl From<Floor> for Dungeon { // TODO: initalize rest of game state // TODO: How will we randomize enemy type/number per floor? + // For now, just create one enemy a few tiles to the right of the player let enemies = vec![Enemy::new( EnemyType::Zombie, - Pos::new(player.entity.pos.x() + 4, player.entity.pos.y()).unwrap(), + Pos::new(player.entity.pos.x() + 4, player.entity.pos.y()) + .unwrap_or(const_pos!(1, 1)), )]; Self { diff --git a/dungeon/src/map.rs b/dungeon/src/map.rs index 212dd00..f4a8729 100644 --- a/dungeon/src/map.rs +++ b/dungeon/src/map.rs @@ -52,7 +52,7 @@ impl Default for Tile { /// The `Floor` type represents the current playing /// grid of the dungeon. It contains the tiles of the /// grid, and the starting position of the player. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct Floor { /// The dungeon grid tiles: Box<[Tile; TILE_COUNT]>, |