Working mostly correct now, just need to tweak how it works more and work on connections.

main
Zed A. Shaw 2 months ago
parent 61d2747441
commit e1ebea7451
  1. 4
      main.cpp
  2. 26
      map.cpp

@ -24,9 +24,9 @@ int main() {
using namespace ftxui;
std::string reset_position;
auto c = Canvas(150, 100);
auto c = Canvas(60 * 2, 50 * 4);
Map game_map(50, 20);
Map game_map(60, 50);
game_map.generate();
Matrix &input_map = game_map.input_map();
Matrix &walls = game_map.walls();

@ -120,8 +120,8 @@ inline int make_split(std::mt19937 &gen, Partition &cur, bool horiz) {
println("MAKE SPLIT horiz={}, y={}, w={}, h={}", horiz,
cur.y, cur.width, cur.height);
size_t dimension = horiz ? cur.height : cur.width;
int min = dimension / 4; // 25% of the dimension
int max = dimension - min; // 25% off the other side
int min = dimension / 4;
int max = dimension - min;
println("dimension={}, min={}, max={}", dimension, min, max);
std::uniform_int_distribution<int> rand_dim(min, max);
return rand_dim(gen);
@ -176,16 +176,21 @@ void partition_map(std::mt19937 &gen, Partition &cur, int depth) {
};
}
if(depth > 0 && left.width > 5 && left.height > 5) {
println("### LEFT h={}, w={}", left.width, left.height);
if(depth > 0 && left.width > 4 && left.height > 4) {
println("DOWN LEFT h={}, w={}", left.height, left.width);
partition_map(gen, left, depth-1);
cur.next.push_back(left);
} else {
println("!!!!LEAF LEFT ROOM h={}, w={}", left.height, left.width);
}
if(depth > 0 && right.width > 5 && right.height > 5) {
println("### RIGHT h={}, w={}", right.width, right.height);
if(depth > 0 && right.width >= 4 && right.height >= 4) {
println("DOWN RIGHT h={}, w={}", right.height, right.width);
partition_map(gen, right, depth-1);
cur.next.push_back(right);
} else {
println("!!!!LEAF RIGHT ROOM h={}, w={}", right.height, right.width);
}
}
@ -193,13 +198,16 @@ void draw_map(Map *map, Partition &cur) {
if(cur.x + cur.width <= map->width()
&& cur.y + cur.height <= map->height())
{
map->make_room(cur.x, cur.y, cur.width, cur.height);
if(cur.next.size() == 2) {
println("CUR NEXT SIZE: {}", cur.next.size());
if(cur.next.size() == 1) {
draw_map(map, cur.next[0]); // left
} else if(cur.next.size() == 2) {
draw_map(map, cur.next[0]); // left
draw_map(map, cur.next[1]); // right
} else {
println("LEAF NODE NO CHILDREN");
println("LEAF NODE NO CHILDREN x={}, y={}, w={}, h={}", cur.x, cur.y, cur.width, cur.height);
map->make_room(cur.x+1, cur.y+1, cur.width-2, cur.height-2);
}
} else {
println("ABORT in draw_map, x={}, y={}, w={}, h={}, map.w={}, map.h={}",

Loading…
Cancel
Save