Mostly cleaned up world get to handle more rooms and paths, but rando_rect needs to be actually random.
This commit is contained in:
parent
c19c53b15b
commit
e9277bf052
11 changed files with 257 additions and 39 deletions
60
matrix.hpp
60
matrix.hpp
|
@ -3,8 +3,12 @@
|
|||
#include <queue>
|
||||
#include <string>
|
||||
#include <array>
|
||||
#include <numeric>
|
||||
#include <algorithm>
|
||||
#include <fmt/core.h>
|
||||
#include "point.hpp"
|
||||
#include "rand.hpp"
|
||||
#include "dbc.hpp"
|
||||
|
||||
namespace matrix {
|
||||
using std::vector, std::queue, std::array;
|
||||
|
@ -324,4 +328,60 @@ namespace matrix {
|
|||
};
|
||||
|
||||
using circle = circle_t<Matrix>;
|
||||
|
||||
template<typename MAT>
|
||||
struct rectangle_t {
|
||||
int x;
|
||||
int y;
|
||||
int left;
|
||||
int right;
|
||||
int width;
|
||||
int height;
|
||||
int bottom;
|
||||
|
||||
rectangle_t(MAT &mat, size_t start_x, size_t start_y, size_t width, size_t height) :
|
||||
left(start_x),
|
||||
width(width),
|
||||
height(height)
|
||||
{
|
||||
size_t h = matrix::height(mat);
|
||||
size_t w = matrix::width(mat);
|
||||
y = start_y - 1;
|
||||
x = left - 1; // must be -1 for next()
|
||||
right = min(start_x + width, w);
|
||||
|
||||
y = start_y;
|
||||
bottom = min(start_y + height, h);
|
||||
}
|
||||
|
||||
bool next() {
|
||||
x = next_x(x, right);
|
||||
y = next_y(x, y);
|
||||
x = max(x, left);
|
||||
return at_end(y, bottom);
|
||||
}
|
||||
};
|
||||
|
||||
using rectangle = rectangle_t<Matrix>;
|
||||
|
||||
template<typename MAT>
|
||||
struct rando_rect_t {
|
||||
int x;
|
||||
int y;
|
||||
rectangle_t<MAT> it;
|
||||
|
||||
rando_rect_t(MAT &mat, size_t start_x, size_t start_y, size_t width, size_t height) :
|
||||
it{mat, start_x, start_y, width, height}
|
||||
{
|
||||
}
|
||||
|
||||
bool next() {
|
||||
bool done = it.next();
|
||||
x = it.x;
|
||||
y = it.y;
|
||||
return done;
|
||||
}
|
||||
};
|
||||
|
||||
using rando_rect = rando_rect_t<Matrix>;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue