Fix crash during map generation
This commit is contained in:
parent
bfa0105ebf
commit
70bc5cfc04
@ -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<Tile> Map::generate_tiles(const std::vector<Tile> &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;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user