diff --git a/src/Map.cpp b/src/Map.cpp index 3a1b39d..59d2d2d 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -15,6 +15,7 @@ Map::Map(GameRenderer *renderer, int tile_size) : int y = renderer->screen_height / tile_size / 2; for (unsigned int x = 0; x < tiles.size(); x++) { if (rand() % 2 == 0) y += rand() % 3 - 1; + y = std::clamp(y, 0, (int)tiles.size() - 1); tiles[x][y] = Tile::path; } @@ -23,6 +24,7 @@ Map::Map(GameRenderer *renderer, int tile_size) : int x = renderer->screen_width / tile_size / 2; for (unsigned int y = 0; y < tiles[x].size(); y++) { if (rand() % 2 == 0) x += rand() % 3 - 1; + x = std::clamp(x, 0, (int)tiles[x].size() - 1); tiles[x][y] = Tile::path; } @@ -38,6 +40,7 @@ std::vector Map::generate_tiles(const std::vector &prev_tiles) const } if (rand() % 2 == 0) path_idx += rand() % 3 - 1; + path_idx = std::clamp(path_idx, 0, (int)prev_tiles.size() - 1); new_tiles[path_idx] = Tile::path;