I can make a map with one room 'randomly' generated and calculate paths.

main
Zed A. Shaw 10 months ago
parent 8b67a25732
commit 6cb3366912
  1. 10
      main.cpp
  2. 25
      map.cpp
  3. 20
      map.hpp
  4. 10
      status.txt
  5. 7
      tests/map.cpp

@ -39,7 +39,7 @@ int main() {
using namespace ftxui;
std::string reset_position;
auto c = Canvas(100, 100);
auto c = Canvas(150, 100);
Map game_map = Map(input, walls, 1000);
@ -53,13 +53,13 @@ int main() {
const string tile = val == 1000 ? "#" : fmt::format("{}", result[y][x]);
c.DrawText(22+x*2, 24+y*4, tile);
c.DrawText(x*2, y*4, tile);
}
}
c.DrawText(20+4*2, 20+3*4, "@", Color::Blue);
c.DrawText(4*2, 3*4, "@", Color::Blue);
return canvas(c);
return canvas(c) | border;
});
while (true) {
@ -71,7 +71,7 @@ int main() {
) | xflex_grow
),
separator(),
hflow(map->Render()),
hbox(map->Render()),
}) | border;
auto screen = Screen::Create(Dimension::Full());

@ -34,6 +34,11 @@ inline void add_neighbors(PairList &neighbors, Matrix &closed, size_t j, size_t
}
}
Map::Map(size_t width, size_t height) : m_limit(1000) {
m_walls = Matrix(height, MatrixRow(width, 1));
m_input_map = Matrix(height, MatrixRow(width, 1));
}
void Map::make_paths() {
size_t h = m_input_map.size();
size_t w = m_input_map[0].size();
@ -42,7 +47,7 @@ void Map::make_paths() {
// NOTE: this is normally ones() * limit
int limit = m_limit == 0 ? h * w : m_limit;
Matrix new_arr = Matrix(h, MatrixRow(w, limit));
Matrix closed = m_walls_map;
Matrix closed = m_walls;
PairList starting_pixels;
PairList open_pixels;
@ -80,3 +85,21 @@ void Map::make_paths() {
m_paths = new_arr;
}
void Map::make_room(size_t origin_x, size_t origin_y, size_t width, size_t height) {
for(size_t y = origin_y; y < origin_y + height; ++y) {
for(size_t x = origin_x; x < origin_x + width; ++x) {
m_walls[y][x] = 0;
}
}
}
void Map::generate() {
size_t w = width();
size_t h = height();
size_t half_w = w / 2;
size_t half_h = h / 2;
make_room(half_w - 5, half_h - 5, 5, 5);
}

@ -17,7 +17,7 @@ void add_neighbors(Matrix &closed, size_t j, size_t i);
class Map {
Matrix m_input_map;
Matrix m_walls_map;
Matrix m_walls;
Matrix m_paths;
int m_limit = 0;
public:
@ -26,13 +26,27 @@ public:
Matrix& paths() { return m_paths; }
Matrix& input_map() { return m_input_map; }
Matrix& walls() { return m_walls_map; }
Matrix& walls() { return m_walls; }
int limit() { return m_limit; }
size_t width() { return m_walls[0].size(); }
size_t height() { return m_walls.size(); }
void make_room(size_t origin_y, size_t origin_x, size_t width, size_t height);
void dump() {
dump_map("PATHS", m_paths);
dump_map("WALLS", m_walls);
dump_map("INPUT", m_input_map);
}
void generate();
Map(Matrix input_map, Matrix walls_map, int limit) :
m_input_map(input_map),
m_walls_map(walls_map), m_limit(limit) {
m_walls(walls_map), m_limit(limit) {
}
Map(size_t width, size_t height);
Map(Map &map) = delete;
};

@ -1,8 +1,8 @@
TODO:
* Create a map gen of some kind.
* Research how hard to create a non-terminal/graphic backend to FTXUI.
* Look into font rendering libraries.
* Get a basic UI in FTX with a stat panel and map.
* Fill the map with something.
* Dijkstra's algorithm for the map.
* https://github.com/HenrYxZ/dijkstra-map/blob/main/dijkstra_map.py
* Look at a few more rogue games
* Lua integration

@ -34,3 +34,10 @@ TEST_CASE("dijkstra algo test", "[map]") {
REQUIRE(paths == expected);
}
}
TEST_CASE("bsp algo test", "[map]") {
Map map(20, 20);
map.generate();
map.dump();
}

Loading…
Cancel
Save