Skip to content

Commit

Permalink
Divide Map::drawBackground method.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek83 committed Sep 28, 2024
1 parent 447637e commit a79cd60
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
37 changes: 18 additions & 19 deletions src/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,30 +240,29 @@ void Map::shiftDown(Point& point, int tileSize)
point.y_ = (point.y_ / tileSize + 1) * tileSize;
}

void Map::drawBackgroundTile(const Screen& screen, TilePosition position)
{
const auto& tile{getTileUsingPosition(position)};
if (tile->isPartOfBackground())
{
tile->draw(screen);
changedTiles_[position.x_][position.y_] = false;
}
else
{
plainTile_->setLocation(tilePositionToScreenPoint(position));
plainTile_->draw(screen);
}
}
void Map::drawBackground(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;
}

else
{
plainTile_->setLocation(tilePositionToScreenPoint({x, y}));
plainTile_->draw(screen);
}
}
if (changedTiles_[x][y])
drawBackgroundTile(screen, {x, y});
}

void Map::drawTile(const Screen& screen, TilePosition position)
void Map::drawForegroundTile(const Screen& screen, TilePosition position)
{
const auto& tile{getTileUsingPosition(position)};
if (!tile->isPartOfBackground())
Expand All @@ -277,7 +276,7 @@ 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])
drawTile(screen, {x, y});
drawForegroundTile(screen, {x, y});
}

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

bool isValidSign(char sign) const;

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

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

Expand Down

0 comments on commit a79cd60

Please sign in to comment.