55#include < spaced/scenes/home.hpp>
66#include < spaced/services/scene_switcher.hpp>
77#include < spaced/services/styles.hpp>
8+ #include < spaced/ui/button.hpp>
9+ #include < spaced/ui/dialog.hpp>
810
911namespace spaced {
1012using bave::Action;
@@ -59,6 +61,7 @@ void Game::tick(Seconds const dt) {
5961 auto ft = bave::DeltaTime{};
6062
6163 m_world.tick (dt);
64+ if (m_world.player .health .is_dead () && !m_game_over_dialog_pushed) { on_game_over (); }
6265
6366 if constexpr (bave::debug_v) { inspect (dt, ft.update ()); }
6467}
@@ -70,6 +73,19 @@ void Game::add_score(std::int64_t const score) {
7073 m_hud->set_score (m_score);
7174}
7275
76+ void Game::on_game_over () {
77+ auto dci = ui::DialogCreateInfo{
78+ .size = {600 .0f , 200 .0f },
79+ .content_text = " GAME OVER" ,
80+ .main_button = {.text = " RESTART" , .callback = [this ] { get_services ().get <ISceneSwitcher>().switch_to <Game>(); }},
81+ .second_button = {.text = " QUIT" , .callback = [this ] { get_app ().shutdown (); }},
82+ };
83+
84+ auto dialog = std::make_unique<ui::Dialog>(get_services (), std::move (dci));
85+ m_game_over_dialog_pushed = true ;
86+ push_view (std::move (dialog));
87+ }
88+
7389void Game::inspect (Seconds const dt, Seconds const frame_time) {
7490 if constexpr (bave::imgui_v) {
7591 m_debug.fps .tick (dt);
@@ -83,6 +99,9 @@ void Game::inspect(Seconds const dt, Seconds const frame_time) {
8399 ImGui::Separator ();
84100 im_text (" score: {}" , get_score ());
85101
102+ ImGui::Separator ();
103+ if (ImGui::Button (" end game" )) { m_world.player .on_death ({}); }
104+
86105 ImGui::Separator ();
87106 im_text (" dt: {:05.2f}" , std::chrono::duration<float , std::milli>(dt).count ());
88107 im_text (" fps: {}" , m_debug.fps .fps );
0 commit comments