Compare commits
No commits in common. "b62df4c79d8f5ea31b5ccdd7218462659029bd99" and "e720189f3e1d6b7619e6a6a3b0a095b5148c00cc" have entirely different histories.
b62df4c79d
...
e720189f3e
|
@ -109,7 +109,11 @@ impl Display for DungeonLevel {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
for y in 0..LEVEL_SIZE.1 {
|
for y in 0..LEVEL_SIZE.1 {
|
||||||
for x in 0..LEVEL_SIZE.0 {
|
for x in 0..LEVEL_SIZE.0 {
|
||||||
write!(f, "{}", self.render_tile(x, y))?;
|
write!(
|
||||||
|
f,
|
||||||
|
"{}",
|
||||||
|
self.render_tile(x, y)
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(f, "\n")?;
|
write!(f, "\n")?;
|
||||||
|
|
20
src/rooms.rs
20
src/rooms.rs
|
@ -5,9 +5,9 @@
|
||||||
//! of attempts to place rectangular rooms of random sizes and
|
//! of attempts to place rectangular rooms of random sizes and
|
||||||
//! positions within the region; of these attempts, we only keep those
|
//! positions within the region; of these attempts, we only keep those
|
||||||
//! that are spread some distance away from other existing rooms. We
|
//! that are spread some distance away from other existing rooms. We
|
||||||
//! then use a pathfinding algorithm to navigate from each room to the
|
//! then use a pathfinding algorithm to navigate from one room to all
|
||||||
//! one generated after it, leaving hallways and doors as we travel.
|
//! the others, leaving hallways and doors as we travel. The
|
||||||
//! The pathfinding algorithm is weighted to try and travel through
|
//! pathfinding algorithm is weighted to try and travel through
|
||||||
//! existing rooms and hallways rather than cutting new hallways
|
//! existing rooms and hallways rather than cutting new hallways
|
||||||
//! through the stone to encourage rooms to connect to other rooms
|
//! through the stone to encourage rooms to connect to other rooms
|
||||||
//! near them, and it has some randomness added to its weights to
|
//! near them, and it has some randomness added to its weights to
|
||||||
|
@ -138,9 +138,7 @@ impl RoomBounds {
|
||||||
);
|
);
|
||||||
|
|
||||||
let new_room = Self { ul_corner, size };
|
let new_room = Self { ul_corner, size };
|
||||||
if v.iter()
|
if v.iter().all(|room| !room.near(&new_room, ROOM_MIN_DISTANCE)) {
|
||||||
.all(|room| !room.near(&new_room, ROOM_MIN_DISTANCE))
|
|
||||||
{
|
|
||||||
v.push(new_room)
|
v.push(new_room)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,12 +175,10 @@ fn cut_hallways(grid: &mut Grid<DungeonTile>, rooms: &[RoomBounds], rng: &mut im
|
||||||
}
|
}
|
||||||
|
|
||||||
let size = (grid.cols(), grid.rows());
|
let size = (grid.cols(), grid.rows());
|
||||||
|
let origin = rooms[0].center();
|
||||||
|
|
||||||
// Make hallways between pairs of adjacent rooms.
|
for other in rooms.iter().skip(1) {
|
||||||
for rooms in rooms.windows(2) {
|
|
||||||
let (from, to) = (&rooms[0], &rooms[1]);
|
|
||||||
let neighbors = [(-1, 0), (1, 0), (0, -1), (0, 1)];
|
let neighbors = [(-1, 0), (1, 0), (0, -1), (0, 1)];
|
||||||
|
|
||||||
for (x, y) in pathfind(
|
for (x, y) in pathfind(
|
||||||
|node| {
|
|node| {
|
||||||
let (x, y) = (node.0 as isize, node.1 as isize);
|
let (x, y) = (node.0 as isize, node.1 as isize);
|
||||||
|
@ -203,8 +199,8 @@ fn cut_hallways(grid: &mut Grid<DungeonTile>, rooms: &[RoomBounds], rng: &mut im
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
from.center(),
|
origin,
|
||||||
to.center(),
|
other.center(),
|
||||||
)
|
)
|
||||||
.expect("graph is connected, must therefore be navigable")
|
.expect("graph is connected, must therefore be navigable")
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue