-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameui.cpp
More file actions
34 lines (24 loc) · 1010 Bytes
/
gameui.cpp
File metadata and controls
34 lines (24 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "gameui.h"
GameUI::GameUI(GameManager *GM, QRect windowRect)
: GM(GM), windowRect(windowRect){ }
void GameUI::drawUI(QPainter *painter)
{
painter->resetTransform();
painter->setPen(QColor(255, 0, 0));
drawLives(painter);
drawScore(painter);
}
void GameUI::drawLives(QPainter* painter)
{
QString lifeText = QString("Lives: ");
lifeText.append(QString::fromStdString(std::to_string(GM->getLivesLeft())));
QRect textBounds = painter->fontMetrics().boundingRect(lifeText);
painter->drawText(UI_TEXT_BORDER, textBounds.height() + UI_TEXT_BORDER, lifeText);
}
void GameUI::drawScore(QPainter* painter)
{
QString scoreText = QString("Score: ");
scoreText.append(QString::fromStdString(std::to_string(GM->getScore())));
QRect textBounds = painter->fontMetrics().boundingRect(scoreText);
painter->drawText(windowRect.width()-textBounds.width() - UI_TEXT_BORDER, textBounds.height() + UI_TEXT_BORDER, scoreText);
}