diff options
| author | fschildt <florian.schildt@protonmail.com> | 2025-10-01 14:08:24 +0200 | 
|---|---|---|
| committer | fschildt <florian.schildt@protonmail.com> | 2025-10-01 14:09:13 +0200 | 
| commit | c775ca6133d93ed97359a6a50bd94a5563c740de (patch) | |
| tree | 9d3efb1c7e7538ff9d5cae408d2c29f9dd3daeab /src/games/breakout/Breakout.cpp | |
| parent | 41c2e2ecfcccf62b3c646980dd283848e33a8134 (diff) | |
general refactoring, prepare breakout game
Diffstat (limited to 'src/games/breakout/Breakout.cpp')
| -rw-r--r-- | src/games/breakout/Breakout.cpp | 66 | 
1 files changed, 66 insertions, 0 deletions
diff --git a/src/games/breakout/Breakout.cpp b/src/games/breakout/Breakout.cpp new file mode 100644 index 0000000..65fafd6 --- /dev/null +++ b/src/games/breakout/Breakout.cpp @@ -0,0 +1,66 @@ +#include <games/breakout/Breakout.hpp> + +#include <imgui.h> + + +bool +Breakout::Update(std::vector<SDL_Event>& events) +{ +    for (auto& event : events) { +        if (m_status == pause) { +            ProcessEventDuringPause(event); +        } +        else { +            ProcessEventDuringResume(event); +        } +    } + +    if (m_status == pause) { +        DrawPauseMenu(); +    } +    if (m_status == exit) { +        return false; +    } + +    return true; +} + +void +Breakout::ProcessEventDuringResume(SDL_Event& event) +{ +    switch (event.type) { +    case SDL_EVENT_KEY_DOWN: { +        if (event.key.key == SDLK_ESCAPE) { +            m_status = pause; +        } +    } break; +    default:; +    } +} + +void +Breakout::ProcessEventDuringPause(SDL_Event &event) +{ +    switch (event.type) { +    case SDL_EVENT_KEY_DOWN: { +        if (event.key.key == SDLK_ESCAPE) { +            m_status = resume; +        } +    } break; +    default:; +    } +} + +void +Breakout::DrawPauseMenu() +{ +    ImGui::Begin("BreakoutPause"); +    if (ImGui::Button("Resume")) { +        m_status = resume; +    } +    if (ImGui::Button("Exit")) { +        m_status = exit; +    } +    ImGui::End(); +} +  | 
