Display the number of remaining lives
This commit is contained in:
parent
fedbc153ae
commit
a0780c7a8c
2 changed files with 15 additions and 0 deletions
|
@ -25,6 +25,7 @@ void Canvas::update(const PacMan & pacMan, const Pellets & pellets, const SuperP
|
|||
renderSuperPellets(superPellets);
|
||||
renderPacMan(pacMan);
|
||||
renderScore(score.points);
|
||||
renderLives(score.lives);
|
||||
|
||||
render();
|
||||
}
|
||||
|
@ -85,6 +86,19 @@ void Canvas::renderScore(int score) {
|
|||
window.draw(text);
|
||||
}
|
||||
|
||||
void Canvas::renderLives(int lives) {
|
||||
constexpr PositionInt liveSprite{3, 0};
|
||||
const int x = LEFT_MARGIN + MAZE_WIDTH + LEFT_MARGIN;
|
||||
const int y = maze_texture.getSize().y;
|
||||
|
||||
Sprite pacmanSprite = getSprite(liveSprite);
|
||||
for(int i = 0; i < lives - 1; i++) {
|
||||
PositionInt pos{x + i * pacmanSprite.getTextureRect().width, y};
|
||||
pacmanSprite.setPosition(pos.x, pos.y);
|
||||
window.draw(pacmanSprite);
|
||||
}
|
||||
}
|
||||
|
||||
Rect Canvas::windowDimensions() {
|
||||
return { 0, 0, LEFT_MARGIN + MAZE_WIDTH + SCORE_WIDTH, TOP_MARGIN + MAZE_HEIGHT + BOTTOM_MARGIN };
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ private:
|
|||
void renderSprite(Sprite sprite, Position pos);
|
||||
|
||||
void renderScore(int score);
|
||||
void renderLives(int lives);
|
||||
|
||||
static Rect windowDimensions();
|
||||
static sf::Texture loadTexture(std::string_view path);
|
||||
|
|
Loading…
Reference in a new issue