Generate east and south
This commit is contained in:
parent
a9c6ec5145
commit
991cff858d
21
src/Map.cpp
21
src/Map.cpp
@ -46,12 +46,14 @@ std::vector<Tile> Map::generate_tiles(std::vector<Tile> prev_tiles) const
|
||||
|
||||
void Map::check_bounds(int player_x, int player_y)
|
||||
{
|
||||
// Generate to the left
|
||||
if (tile_offset_x * tile_size + renderer->screen_width > player_x) {
|
||||
const std::vector<Tile> new_tiles = generate_tiles(tiles[0]);
|
||||
tiles.insert(tiles.begin(), new_tiles);
|
||||
tile_offset_x--;
|
||||
}
|
||||
|
||||
// Generate upwards
|
||||
if (tile_offset_y * tile_size + renderer->screen_height > player_y) {
|
||||
std::vector<Tile> prev_tiles;
|
||||
for (int x = 0; x < tiles.size(); x++) {
|
||||
@ -65,6 +67,25 @@ void Map::check_bounds(int player_x, int player_y)
|
||||
|
||||
tile_offset_y--;
|
||||
}
|
||||
|
||||
// Generate to the right
|
||||
if (player_x > (int)(tile_offset_x * tile_size + tiles.size() * tile_size - renderer->screen_width / 2)) {
|
||||
const std::vector<Tile> new_tiles = generate_tiles(tiles.back());
|
||||
tiles.push_back(new_tiles);
|
||||
}
|
||||
|
||||
// Generate downwards
|
||||
if (player_y > (int)(tile_offset_y * tile_size + tiles[0].size() * tile_size - renderer->screen_height / 2)) {
|
||||
std::vector<Tile> prev_tiles;
|
||||
for (int x = 0; x < tiles.size(); x++) {
|
||||
prev_tiles.push_back(tiles[x].back());
|
||||
}
|
||||
|
||||
const std::vector<Tile> new_tiles = generate_tiles(prev_tiles);
|
||||
for (int x = 0; x < tiles.size(); x++) {
|
||||
tiles[x].push_back(new_tiles[x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Map::draw(int player_x, int player_y) const
|
||||
|
||||
Loading…
Reference in New Issue
Block a user