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

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

@ -24,9 +24,9 @@ int main() {
using namespace ftxui; using namespace ftxui;
std::string reset_position; 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(); game_map.generate();
Matrix &input_map = game_map.input_map(); Matrix &input_map = game_map.input_map();
Matrix &walls = game_map.walls(); 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, println("MAKE SPLIT horiz={}, y={}, w={}, h={}", horiz,
cur.y, cur.width, cur.height); cur.y, cur.width, cur.height);
size_t dimension = horiz ? cur.height : cur.width; size_t dimension = horiz ? cur.height : cur.width;
int min = dimension / 4; // 25% of the dimension int min = dimension / 4;
int max = dimension - min; // 25% off the other side int max = dimension - min;
println("dimension={}, min={}, max={}", dimension, min, max); println("dimension={}, min={}, max={}", dimension, min, max);
std::uniform_int_distribution<int> rand_dim(min, max); std::uniform_int_distribution<int> rand_dim(min, max);
return rand_dim(gen); 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) { if(depth > 0 && left.width > 4 && left.height > 4) {
println("### LEFT h={}, w={}", left.width, left.height); println("DOWN LEFT h={}, w={}", left.height, left.width);
partition_map(gen, left, depth-1); partition_map(gen, left, depth-1);
cur.next.push_back(left); 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); partition_map(gen, right, depth-1);
cur.next.push_back(right); 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() if(cur.x + cur.width <= map->width()
&& cur.y + cur.height <= map->height()) && 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[0]); // left
draw_map(map, cur.next[1]); // right draw_map(map, cur.next[1]); // right
} else { } 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 { } else {
println("ABORT in draw_map, x={}, y={}, w={}, h={}, map.w={}, map.h={}", println("ABORT in draw_map, x={}, y={}, w={}, h={}, map.w={}, map.h={}",

Loading…
Cancel
Save