summaryrefslogtreecommitdiff
path: root/dungeon
diff options
context:
space:
mode:
authoralf9310 <alf9310@rit.edu>2025-11-06 12:20:57 -0500
committeralf9310 <alf9310@rit.edu>2025-11-06 12:20:57 -0500
commit763b047c92a5d5340bad38506862ad6c87ecdbe9 (patch)
tree68b391d3745458005eade3c07ac9e41655376d5c /dungeon
parentMoved most of the movement stuff to entity. (diff)
downloadDungeonCrawl-763b047c92a5d5340bad38506862ad6c87ecdbe9.tar.gz
DungeonCrawl-763b047c92a5d5340bad38506862ad6c87ecdbe9.tar.bz2
DungeonCrawl-763b047c92a5d5340bad38506862ad6c87ecdbe9.zip
Light bsp refactoring
Diffstat (limited to 'dungeon')
-rw-r--r--dungeon/src/bsp.rs7
-rw-r--r--dungeon/src/lib.rs14
-rw-r--r--dungeon/src/map.rs2
-rw-r--r--dungeon/tests/bsp_tests.rs15
4 files changed, 28 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]>,
diff --git a/dungeon/tests/bsp_tests.rs b/dungeon/tests/bsp_tests.rs
new file mode 100644
index 0000000..2e3a781
--- /dev/null
+++ b/dungeon/tests/bsp_tests.rs
@@ -0,0 +1,15 @@
+//! Integration Tests for BSP dungeon generation
+#[cfg(test)]
+mod tests {
+ use dungeon::*;
+
+ #[test]
+ fn test_bsp_integration() {
+ let seed = 12345u64;
+ let (tiles, player_start) = bsp::generate(seed);
+ // Basic integration test: ensure we get valid data
+ assert!(!tiles.is_empty());
+ assert!(player_start.x() < map::MAP_SIZE);
+ assert!(player_start.y() < map::MAP_SIZE);
+ }
+}