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

This commit is contained in:
Zed A. Shaw 2024-09-27 00:10:41 -04:00
parent 8b67a25732
commit 6cb3366912
5 changed files with 58 additions and 14 deletions

25
map.cpp
View file

@ -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);
}