@@ -24,51 +24,60 @@ HUD :: HUD(Window* window, Input* input, Cache<Resource,std::string>* cache, Pla
24
24
cache
25
25
);
26
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);
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
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 ));
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
33
34
- m_pStarText->align (Text::LEFT);
35
- m_pLivesText->align (Text::CENTER);
36
- m_pHealthText->align (Text::RIGHT);
34
+ m_pStarText->align (Text::LEFT);
35
+ m_pLivesText->align (Text::CENTER);
36
+ m_pHealthText->align (Text::RIGHT);
37
37
38
38
add (m_pStarText);
39
- add (m_pLivesText);
40
- add (m_pHealthText);
39
+ add (m_pLivesText);
40
+ add (m_pHealthText);
41
41
42
42
set (0 , 0 , 0 );
43
43
44
44
auto _this = this ;
45
45
m_HealthCon = m_pPlayer->on_health_change .connect ([_this](int ){_this->m_bDirty = true ; });
46
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
-
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
+ );
64
61
62
+ mat = make_shared<MeshMaterial>(" guy-jump.png" , m_pCache);
63
+ m_pGuy = make_shared<Mesh>(
64
+ make_shared<MeshGeometry>(Prefab::quad (vec2 (sw / 24 , sw / 24 ))),
65
+ vector<shared_ptr<IMeshModifier>>{
66
+ make_shared<Wrap>(Prefab::quad_wrap (
67
+ glm::vec2 (0 .0f , 1 .0f ), glm::vec2 (1 .0f , 0 .0f )
68
+ ))
69
+ }, mat
70
+ );
71
+
72
+ add (m_pHeart);
73
+ add (m_pGuy);
65
74
}
66
75
67
76
68
77
void HUD :: redraw() {
69
78
auto sw = m_pWindow->size ().x ;
70
79
auto sh = m_pWindow->size ().y ;
71
-
80
+
72
81
// // clear transparent
73
82
// auto ctext = m_pCanvas->context();
74
83
// m_pCanvas->clear(Color(0.0f, 0.0f, 0.0f, 0.0f));
@@ -84,23 +93,25 @@ void HUD :: redraw() {
84
93
85
94
// m_pCanvas->dirty(true);
86
95
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
-
96
+ m_pStarText->set (" " + to_string (m_Stars) + " /" + to_string (m_MaxStars));
97
+ m_pHealthText->set (to_string (m_pPlayer->health ()) + " %" );
98
+ m_pLivesText->set (" " + to_string (m_pPlayer->lives ()));
99
+
100
+ m_pLivesText->redraw ();
101
+ m_pHealthText->redraw ();
102
+ m_pGuy->position (glm::vec3 (sw/2 .0f - m_pLivesText->size ().x , 0 .0f , 0 .0f ));
103
+ m_pHeart->position (glm::vec3 (sw - m_pHealthText->size ().x - 64 .0f , 0 .0f , 0 .0f ));
92
104
}
93
105
94
-
95
106
void HUD :: logic_self(Freq::Time) {
96
107
if (m_bDirty) {
97
108
redraw ();
98
109
99
- // m_pHeart->position(m_pHealthText->position() - glm::vec3(
110
+ // m_pHeart->position(m_pHealthText->position() - glm::vec3(
100
111
101
- // m_pHealthText->children()[0]->box().size().x, 0.0f, 0.0f
112
+ // m_pHealthText->children()[0]->box().size().x, 0.0f, 0.0f
102
113
103
- // ));
114
+ // ));
104
115
105
116
m_bDirty = false ;
106
117
}
0 commit comments