A dirty first cut at a single random horiz/vert split for the BSP algorithm.

This commit is contained in:
Zed A. Shaw 2024-09-27 18:42:32 -04:00
parent 6cb3366912
commit 62195e6eea
3 changed files with 83 additions and 33 deletions

View file

@ -17,31 +17,21 @@
#include "dbc.hpp"
using std::string;
using namespace fmt;
using namespace std::chrono_literals;
Matrix input = {
{1,1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,0,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1,1},
};
Matrix walls = {
{1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,1,1,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,1,0,1},
{1,0,0,0,0,1,1,0,0,1,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1},
};
int main() {
using namespace ftxui;
std::string reset_position;
auto c = Canvas(150, 100);
Map game_map = Map(input, walls, 1000);
Map game_map(50, 20);
game_map.generate();
Matrix &input_map = game_map.input_map();
Matrix &walls = game_map.walls();
input_map[10][10] = 0;
auto map = Renderer([&] {
game_map.make_paths();
@ -49,15 +39,21 @@ int main() {
for(size_t x = 0; x < result[0].size(); ++x) {
for(size_t y = 0; y < result.size(); ++y) {
auto val = result[y][x];
const string tile = val == 1000 ? "#" : fmt::format("{}", result[y][x]);
c.DrawText(x*2, y*4, tile);
auto path = result[y][x];
if(path == 1000) {
// it's a wall or unreachable, use the wall_map
const string tile = walls[y][x] == 1 ? "#" : ".";
c.DrawText(x*2, y*4, tile);
} else {
// it's a path number, show it
const string tile = format("{}", path);
c.DrawText(x*2, y*4, tile);
}
}
}
c.DrawText(4*2, 3*4, "@", Color::Blue);
// draw the character
c.DrawText(10*2, 10*4, "@", Color::Blue);
return canvas(c) | border;
});