@@ -23,10 +23,6 @@ Game::Game(gsl::not_null<le::ServiceLocator const*> services) : m_services(servi
2323 auto const & context = services->get <le::Context>();
2424 auto const asset_loader = le::AssetLoader{&data_loader, &context};
2525 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};
3026}
3127
3228void Game::on_cursor_pos (le::event::CursorPos const & cursor_pos) {
@@ -77,13 +73,28 @@ void Game::spawn_wave() {
7773}
7874
7975void 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 ();
8177 m_score_text.transform .position .y = static_cast <float >(framebuffer_size.y ) / 2 .0f - 50 .0f ;
8278 m_score += points;
8379 m_score_str.clear ();
8480 std::format_to (std::back_inserter (m_score_str), " Score: {}" , m_score);
8581 m_score_text.set_string (m_font, m_score_str);
8682}
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+ }
8899
89100} // namespace miracle
0 commit comments