Playing with maze gen again.
This commit is contained in:
parent
c97648ab3a
commit
33cd490ed3
8 changed files with 164 additions and 36 deletions
68
maze.cpp
68
maze.cpp
|
@ -93,16 +93,39 @@ inline std::pair<Point, Point> find_coord(Matrix& maze) {
|
|||
dbc::sentinel("failed to find coord?");
|
||||
}
|
||||
|
||||
void maze::hunt_and_kill(Matrix& maze, std::vector<Room>& rooms, std::vector<Point>& dead_ends) {
|
||||
matrix::assign(maze, WALL_VALUE);
|
||||
void maze::randomize_rooms(std::vector<Room>& rooms_out, std::vector<Point> maybe_here) {
|
||||
dbc::check(maybe_here.size() >= 2, "must have at least two possible points to place rooms");
|
||||
|
||||
Point last_even{0,0};
|
||||
while(rooms_out.size() < 2) {
|
||||
// use those dead ends to randomly place rooms
|
||||
for(auto at : maybe_here) {
|
||||
if(Random::uniform(0,1)) {
|
||||
size_t offset = Random::uniform(0,1);
|
||||
Room cur{at.x+offset, at.y+offset, 1, 1};
|
||||
rooms_out.push_back(cur);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void maze::init(Matrix& maze) {
|
||||
matrix::assign(maze, WALL_VALUE);
|
||||
}
|
||||
|
||||
void maze::divide(Matrix& maze, Point start, Point end) {
|
||||
for(matrix::line it{start, end}; it.next();) {
|
||||
maze[it.y][it.x] = 0;
|
||||
maze[it.y+1][it.x] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void maze::hunt_and_kill(Matrix& maze, std::vector<Room>& rooms, std::vector<Point>& dead_ends, bool init_map) {
|
||||
|
||||
if(init_map) {
|
||||
maze::init(maze);
|
||||
}
|
||||
|
||||
for(auto& room : rooms) {
|
||||
if(room.x % 2 == 0 && room.y % 2 == 0) {
|
||||
last_even = {room.x, room.y};
|
||||
}
|
||||
|
||||
for(matrix::box it{maze, room.x, room.y, room.width}; it.next();) {
|
||||
maze[it.y][it.x] = 0;
|
||||
}
|
||||
|
@ -149,3 +172,34 @@ void maze::hunt_and_kill(Matrix& maze, std::vector<Room>& rooms, std::vector<Poi
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void maze::inner_ring(Matrix& maze, size_t outer_size, size_t inner_size) {
|
||||
|
||||
size_t x = matrix::width(maze) / 2;
|
||||
size_t y = matrix::height(maze) / 2;
|
||||
|
||||
for(matrix::box it{maze, x, y, outer_size};
|
||||
it.next();)
|
||||
{
|
||||
maze[it.y][it.x] = 0;
|
||||
}
|
||||
|
||||
for(matrix::box it{maze, x, y, inner_size};
|
||||
it.next();)
|
||||
{
|
||||
maze[it.y][it.x] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void maze::remove_dead_ends(Matrix& maze, std::vector<Point>& dead_ends) {
|
||||
for(auto at : dead_ends) {
|
||||
for(matrix::compass it{maze, at.x, at.y}; it.next();) {
|
||||
if(maze[it.y][it.x] == 0) {
|
||||
int diff_x = at.x - it.x;
|
||||
int diff_y = at.y - it.y;
|
||||
maze[at.y + diff_y][at.x + diff_x] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue