@@ -23,10 +23,6 @@ Game::Game(gsl::not_null<le::ServiceLocator const*> services) : m_services(servi
23
23
auto const & context = services->get <le::Context>();
24
24
auto const asset_loader = le::AssetLoader{&data_loader, &context};
25
25
m_font = asset_loader.load_font (" fonts/specialElite.ttf" );
26
- auto const framebuffer_size = m_services->get <le::Context>().framebuffer_size ();
27
- auto const y = (static_cast <float >(framebuffer_size.y ) / 2 .0f ) - 50 .0f ;
28
- m_score_text.transform .position .y = y;
29
- m_health_text.transform .position = glm::vec2{(static_cast <float >(framebuffer_size.y ) / 2 .0f ) - 50 .0f , y};
30
26
}
31
27
32
28
void Game::on_cursor_pos (le::event::CursorPos const & cursor_pos) {
@@ -77,13 +73,28 @@ void Game::spawn_wave() {
77
73
}
78
74
79
75
void Game::update_score (int points) {
80
- auto const framebuffer_size = m_services->get <le::Context>().framebuffer_size ();
76
+ auto const & framebuffer_size = m_services->get <le::Context>().framebuffer_size ();
81
77
m_score_text.transform .position .y = static_cast <float >(framebuffer_size.y ) / 2 .0f - 50 .0f ;
82
78
m_score += points;
83
79
m_score_str.clear ();
84
80
std::format_to (std::back_inserter (m_score_str), " Score: {}" , m_score);
85
81
m_score_text.set_string (m_font, m_score_str);
86
82
}
87
- void Game::update_health_text () {}
83
+
84
+ void Game::update_health_text () {
85
+ auto const & framebuffer_size = m_services->get <le::Context>().framebuffer_size ();
86
+ float const x = (static_cast <float >(framebuffer_size.x ) * 0 .5f ) - 150 .0f ;
87
+ float const y = (static_cast <float >(framebuffer_size.y ) * 0 .5f ) - 50 .0f ;
88
+ m_health_text.transform .position = {x, y};
89
+
90
+ m_health_str.clear ();
91
+ if (m_lighthouse.get_health () <= 0 .0f ) {
92
+ std::format_to (std::back_inserter (m_health_str), " Game Over" );
93
+ } else {
94
+ std::format_to (std::back_inserter (m_health_str), " Health: {:.1f}" , m_lighthouse.get_health ());
95
+ }
96
+
97
+ m_health_text.set_string (m_font, m_health_str);
98
+ }
88
99
89
100
} // namespace miracle
0 commit comments