Skip to content

Commit ea5cdbb

Browse files
committed
Merge branch 'develop' of http://github.com/flipcoder/microarmy into develop
2 parents 65dc575 + f44a6f6 commit ea5cdbb

File tree

3 files changed

+50
-38
lines changed

3 files changed

+50
-38
lines changed

src/HUD.cpp

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,51 +24,60 @@ HUD :: HUD(Window* window, Input* input, Cache<Resource,std::string>* cache, Pla
2424
cache
2525
);
2626

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);
3030

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));
3333

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);
3737

3838
add(m_pStarText);
39-
add(m_pLivesText);
40-
add(m_pHealthText);
39+
add(m_pLivesText);
40+
add(m_pHealthText);
4141

4242
set(0, 0, 0);
4343

4444
auto _this = this;
4545
m_HealthCon = m_pPlayer->on_health_change.connect([_this](int){_this->m_bDirty = true; });
4646

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+
);
6461

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);
6574
}
6675

6776

6877
void HUD :: redraw() {
6978
auto sw = m_pWindow->size().x;
7079
auto sh = m_pWindow->size().y;
71-
80+
7281
//// clear transparent
7382
//auto ctext = m_pCanvas->context();
7483
//m_pCanvas->clear(Color(0.0f, 0.0f, 0.0f, 0.0f));
@@ -84,23 +93,25 @@ void HUD :: redraw() {
8493

8594
//m_pCanvas->dirty(true);
8695

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));
92104
}
93105

94-
95106
void HUD :: logic_self(Freq::Time) {
96107
if (m_bDirty) {
97108
redraw();
98109

99-
//m_pHeart->position(m_pHealthText->position() - glm::vec3(
110+
//m_pHeart->position(m_pHealthText->position() - glm::vec3(
100111

101-
// m_pHealthText->children()[0]->box().size().x, 0.0f, 0.0f
112+
// m_pHealthText->children()[0]->box().size().x, 0.0f, 0.0f
102113

103-
//));
114+
//));
104115

105116
m_bDirty = false;
106117
}

src/HUD.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class HUD: public Node {
4747
Cache<Resource, std::string>* m_pCache;
4848
std::shared_ptr<Mesh> m_pMesh;
4949
std::shared_ptr<Mesh> m_pHeart;
50+
std::shared_ptr<Mesh> m_pGuy;
5051

5152
std::shared_ptr<Font> m_pFont;
5253
std::shared_ptr<Text> m_pLivesText;

0 commit comments

Comments
 (0)