Skip to content

Commit 6f51b2c

Browse files
author
Douglas-Robert-Drugan
committed
Added GodMode text with real-time updates to HUD
1 parent 1e865f4 commit 6f51b2c

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

src/HUD.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,27 @@ HUD :: HUD(Window* window, Input* input, Cache<Resource,std::string>* cache, Pla
2727
m_pStarText = std::make_shared<Text>(m_pFont);
2828
m_pLivesText = std::make_shared<Text>(m_pFont);
2929
m_pHealthText = std::make_shared<Text>(m_pFont);
30+
m_pGodText = std::make_shared<Text>(m_pFont);
3031

3132
m_pLivesText->position(glm::vec3(sw / 2.0f, 0.0f, 0.0f));
3233
m_pHealthText->position(glm::vec3(sw, 0.0f, 0.0f));
34+
m_pGodText->position(glm::vec3(0.0f, sh *.1, 0.2f));
3335

3436
m_pStarText->align(Text::LEFT);
3537
m_pLivesText->align(Text::CENTER);
3638
m_pHealthText->align(Text::RIGHT);
39+
m_pGodText->align(Text::LEFT);
3740

3841
add(m_pStarText);
3942
add(m_pLivesText);
4043
add(m_pHealthText);
44+
add(m_pGodText);
4145

4246
set(0, 0, 0);
4347

4448
auto _this = this;
4549
m_HealthCon = m_pPlayer->on_health_change.connect([_this](int){_this->m_bDirty = true; });
50+
m_GodCon = m_pPlayer->on_god_change.connect([_this](bool) {_this->m_bDirty = true; });
4651

4752
auto mat = make_shared<MeshMaterial>("items.png", m_pCache);
4853

@@ -96,7 +101,9 @@ void HUD :: redraw() {
96101
m_pStarText->set(" " + to_string(m_Stars) + "/" + to_string(m_MaxStars));
97102
m_pHealthText->set(to_string(m_pPlayer->health()) + "%");
98103
m_pLivesText->set(" " + to_string(m_pPlayer->lives()));
99-
104+
m_pGodText->set("God Mode: " + to_string(m_pPlayer->god()));
105+
106+
m_pGodText->redraw();
100107
m_pLivesText->redraw();
101108
m_pHealthText->redraw();
102109
m_pGuy->position(glm::vec3(sw/2.0f - m_pLivesText->size().x, 0.0f, 0.0f));

src/HUD.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ class HUD: public Node {
5353
std::shared_ptr<Text> m_pLivesText;
5454
std::shared_ptr<Text> m_pHealthText;
5555
std::shared_ptr<Text> m_pStarText;
56+
std::shared_ptr<Text> m_pGodText;
5657
Player* m_pPlayer = nullptr;
5758

5859
boost::signals2::scoped_connection m_HealthCon;
60+
boost::signals2::scoped_connection m_GodCon;
5961

6062
// Functions
6163
void redraw();

src/Player.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void Player :: logic_self(Freq::Time t) {
129129
m_NoFatalObjects = !m_NoFatalObjects;
130130

131131
if (m_pController->button("God").pressed_now())
132-
m_GodMode = !m_GodMode;
132+
god(!m_GodMode);
133133

134134
if (m_pController->button("NextLevel").pressed_now())
135135
next_level();

src/Player.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Player: public Node {
5050
void shoot(glm::vec2 dir);
5151
void face(glm::vec2 dir);
5252
void battery(int b) { m_Battery += b; }
53-
void god(bool b) { m_GodMode = b; }
53+
void god(bool b) { m_GodMode = b; on_god_change(m_GodMode);}
5454
void blinking(bool b) { m_Blinking = b; }
5555
void blink();
5656
void reset();
@@ -69,6 +69,7 @@ class Player: public Node {
6969
Sprite* sprite() { return m_pChar.get(); }
7070

7171
boost::signals2::signal<void(int)> on_health_change;
72+
boost::signals2::signal<void(bool)> on_god_change;
7273

7374
private:
7475
// Variables

0 commit comments

Comments
 (0)