-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHUDController.cpp
More file actions
40 lines (27 loc) · 1.04 KB
/
HUDController.cpp
File metadata and controls
40 lines (27 loc) · 1.04 KB
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
35
36
37
38
39
40
#include "HUDController.h"
#include "HUDModel.h"
#include "GUITextureRenderComponent.h"
HUDController::HUDController() {
m_xWinText = nullptr;
m_xLoseText = nullptr;
HUDModel::instance()->registerEventHandler(Event::HUD_UPDATE, this, &HUDController::update);
}
HUDController::~HUDController() {
HUDModel::instance()->removeEventHandler(Event::HUD_UPDATE, this, &HUDController::update);
}
void HUDController::init(GameObject* healthBar, GameObject* winText, GameObject* loseText) {
m_xHealthBar = healthBar;
m_xWinText = static_cast<GUITextureRenderComponent*>(winText->getComponent(Component::RENDER));
m_xLoseText = static_cast<GUITextureRenderComponent*>(loseText->getComponent(Component::RENDER));
m_xWinText->setVisible(false);
m_xLoseText->setVisible(false);
}
void HUDController::update(const Event& e) {
m_xHealthBar->setScale(glm::vec3(
HUDModel::instance()->getHPFactor(),
1.0f,
1.0f
));
m_xWinText->setVisible(HUDModel::instance()->getScore() == 64);
m_xLoseText->setVisible(HUDModel::instance()->getHPFactor() <= 0.0f);
}