Skip to content

Commit

Permalink
Divide method Map::drawForeground.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek83 committed Sep 28, 2024
1 parent a9c5f75 commit 48e5f85
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,21 +263,21 @@ void Map::drawBackground(const Screen& screen)
}
}

void Map::drawTile(const Screen& screen, TilePosition position)
{
const auto& tile{getTileUsingPosition(position)};
if (!tile->isPartOfBackground())
{
tile->draw(screen);
changedTiles_[position.x_][position.y_] = false;
}
}
void Map::drawForeground(const Screen& screen)
{
for (std::size_t x = 0; x < mapDimension_; ++x)
for (std::size_t y = 0; y < mapDimension_; ++y)
{
if (!changedTiles_[x][y])
continue;

const auto& tile{getTileUsingPosition({x, y})};
if (!tile->isPartOfBackground())
{
tile->draw(screen);
changedTiles_[x][y] = false;
}
}
if (changedTiles_[x][y])
drawTile(screen, {x, y});
}

bool Map::isBaseDestroyed() const { return baseDestroyed_; }
Expand Down
2 changes: 2 additions & 0 deletions src/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class Map

bool isTileSign(char sign) const;

void drawTile(const Screen& screen, TilePosition position);

std::vector<std::vector<std::unique_ptr<Tile>>> board_{};

std::vector<std::vector<bool>> changedTiles_{};
Expand Down

0 comments on commit 48e5f85

Please sign in to comment.