From c775ca6133d93ed97359a6a50bd94a5563c740de Mon Sep 17 00:00:00 2001 From: fschildt Date: Wed, 1 Oct 2025 14:08:24 +0200 Subject: general refactoring, prepare breakout game --- src/games/breakout/Breakout.cpp | 66 +++++++++++++++++++++++++++++++++++++++++ src/games/breakout/Breakout.hpp | 38 ++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 src/games/breakout/Breakout.cpp create mode 100644 src/games/breakout/Breakout.hpp (limited to 'src/games/breakout') 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 + +#include + + +bool +Breakout::Update(std::vector& 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(); +} + diff --git a/src/games/breakout/Breakout.hpp b/src/games/breakout/Breakout.hpp new file mode 100644 index 0000000..9f2a0ef --- /dev/null +++ b/src/games/breakout/Breakout.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include +#include +#include + + +struct Ball { + V3F32 pos; + float radius; +}; + + +class Breakout : public Game { + enum GameStatus { + resume, + pause, + exit + }; + +public: + Breakout() = default; + bool Update(std::vector &events) override; + +private: + void ProcessEventDuringPause(SDL_Event& event); + void ProcessEventDuringResume(SDL_Event& event); + + void Draw(); + void DrawPauseMenu(); + + +private: + GameStatus m_status; + + Circle m_circle; +}; + -- cgit v1.2.3