Skip to content

Commit 50fbf69

Browse files
committed
HUD has icons
1 parent d00157e commit 50fbf69

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed

src/HUD.cpp

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,45 @@ HUD :: HUD(Window* window, Input* input, Cache<Resource,std::string>* cache, Pla
2323
to_string(int(sw / 36.0f + 0.5f))),
2424
cache
2525
);
26-
m_pText = std::make_shared<Text>(m_pFont);
27-
add(m_pText);
28-
26+
27+
m_pStarText = std::make_shared<Text>(m_pFont);
28+
m_pLivesText = std::make_shared<Text>(m_pFont);
29+
m_pHealthText = std::make_shared<Text>(m_pFont);
30+
31+
m_pLivesText->position(glm::vec3(sw / 2.0f, 0.0f, 0.0f));
32+
m_pHealthText->position(glm::vec3(sw, 0.0f, 0.0f));
33+
34+
m_pStarText->align(Text::LEFT);
35+
m_pLivesText->align(Text::CENTER);
36+
m_pHealthText->align(Text::RIGHT);
37+
38+
add(m_pStarText);
39+
add(m_pLivesText);
40+
add(m_pHealthText);
41+
2942
set(0, 0, 0);
3043

3144
auto _this = this;
3245
m_HealthCon = m_pPlayer->on_health_change.connect([_this](int){_this->m_bDirty = true; });
46+
47+
auto mat = make_shared<MeshMaterial>("items.png", m_pCache);
48+
49+
m_pHeart = make_shared<Mesh>(
50+
make_shared<MeshGeometry>(Prefab::quad(vec2(sw / 24, sw / 24))),
51+
vector<shared_ptr<IMeshModifier>>{
52+
make_shared<Wrap>(Prefab::tile_wrap(
53+
// Y Y (height is tile size for both dims)
54+
uvec2(16, 16),
55+
// X Y
56+
uvec2(mat->texture()->size().x, mat->texture()->size().y),
57+
1
58+
))
59+
}, mat
60+
);
61+
62+
add(m_pHeart);
63+
64+
3365
}
3466

3567

@@ -52,15 +84,24 @@ void HUD :: redraw() {
5284

5385
//m_pCanvas->dirty(true);
5486

55-
m_pText->set(" " + to_string(m_Stars) + "/" + to_string(m_MaxStars) + "\n"
56-
+ "Health: " + to_string(m_pPlayer->health()) + "/100" + "\n"
57-
+ "Lives: " + to_string(m_pPlayer->lives()));
87+
m_pStarText->set(" " + to_string(m_Stars) + "/" + to_string(m_MaxStars));
88+
m_pHealthText->set(" " + to_string(m_pPlayer->health()) + "%");
89+
m_pLivesText->set(" " + to_string(m_pPlayer->lives()));
90+
91+
5892
}
5993

6094

6195
void HUD :: logic_self(Freq::Time) {
6296
if (m_bDirty) {
6397
redraw();
98+
99+
//m_pHeart->position(m_pHealthText->position() - glm::vec3(
100+
101+
// m_pHealthText->children()[0]->box().size().x, 0.0f, 0.0f
102+
103+
//));
104+
64105
m_bDirty = false;
65106
}
66107
}

src/HUD.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ class HUD: public Node {
4646
//std::shared_ptr<Canvas> m_pCanvas;
4747
Cache<Resource, std::string>* m_pCache;
4848
std::shared_ptr<Mesh> m_pMesh;
49+
std::shared_ptr<Mesh> m_pHeart;
4950

5051
std::shared_ptr<Font> m_pFont;
51-
std::shared_ptr<Text> m_pText;
52+
std::shared_ptr<Text> m_pLivesText;
53+
std::shared_ptr<Text> m_pHealthText;
54+
std::shared_ptr<Text> m_pStarText;
5255
Player* m_pPlayer = nullptr;
5356

5457
boost::signals2::scoped_connection m_HealthCon;

0 commit comments

Comments
 (0)