Randomized rectangle placement without repetition works now. On to having multiple levels in the dungeon.

main
Zed A. Shaw 1 week ago
parent cb976a69a9
commit ffdea41faa
  1. 12
      matrix.hpp

@ -333,13 +333,15 @@ namespace matrix {
struct rectangle_t { struct rectangle_t {
int x; int x;
int y; int y;
int top;
int left; int left;
int right;
int width; int width;
int height; int height;
int right;
int bottom; int bottom;
rectangle_t(MAT &mat, size_t start_x, size_t start_y, size_t width, size_t height) : rectangle_t(MAT &mat, size_t start_x, size_t start_y, size_t width, size_t height) :
top(start_y),
left(start_x), left(start_x),
width(width), width(width),
height(height) height(height)
@ -368,17 +370,21 @@ namespace matrix {
struct rando_rect_t { struct rando_rect_t {
int x; int x;
int y; int y;
int x_offset;
int y_offset;
rectangle_t<MAT> it; rectangle_t<MAT> it;
rando_rect_t(MAT &mat, size_t start_x, size_t start_y, size_t width, size_t height) : 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} it{mat, start_x, start_y, width, height}
{ {
x_offset = Random::uniform(0, int(width));
y_offset = Random::uniform(0, int(height));
} }
bool next() { bool next() {
bool done = it.next(); bool done = it.next();
x = it.x; x = it.left + ((it.x + x_offset) % it.width);
y = it.y; y = it.top + ((it.y + y_offset) % it.height);
return done; return done;
} }
}; };

Loading…
Cancel
Save