@@ -23,13 +23,45 @@ HUD :: HUD(Window* window, Input* input, Cache<Resource,std::string>* cache, Pla
23
23
to_string (int (sw / 36 .0f + 0 .5f ))),
24
24
cache
25
25
);
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
+
29
42
set (0 , 0 , 0 );
30
43
31
44
auto _this = this ;
32
45
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
+
33
65
}
34
66
35
67
@@ -52,15 +84,24 @@ void HUD :: redraw() {
52
84
53
85
// m_pCanvas->dirty(true);
54
86
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
+
58
92
}
59
93
60
94
61
95
void HUD :: logic_self(Freq::Time) {
62
96
if (m_bDirty) {
63
97
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
+
64
105
m_bDirty = false ;
65
106
}
66
107
}
0 commit comments