diff options
author | fschildt <florian.schildt@protonmail.com> | 2025-07-21 16:07:28 +0200 |
---|---|---|
committer | fschildt <florian.schildt@protonmail.com> | 2025-07-21 16:07:28 +0200 |
commit | b46a0d9369fbaa1938f0968ab216bc2d564a9c37 (patch) | |
tree | c28b75187d01be9642af56a54a6101f51b25e4a7 /src/games/snake/Snake.hpp |
Diffstat (limited to 'src/games/snake/Snake.hpp')
-rw-r--r-- | src/games/snake/Snake.hpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/games/snake/Snake.hpp b/src/games/snake/Snake.hpp new file mode 100644 index 0000000..f04ad16 --- /dev/null +++ b/src/games/snake/Snake.hpp @@ -0,0 +1,62 @@ +#pragma once + +#include <renderer/RenderGroup.hpp> +#include <games/Game.hpp> + +#include <random> + + +class Snake : public Game { +public: + enum Direction : int32_t { + DIRECTION_UP, + DIRECTION_DOWN, + DIRECTION_LEFT, + DIRECTION_RIGHT, + }; + + +public: + Snake(); + bool Update(std::vector<SDL_Event> &events, RenderGroup &render_group) override; + + +private: + void ProcessEventDuringPause(SDL_Event &event); + void ProcessEventDuringResume(SDL_Event &event); + + void MaybeMoveSnake(float dt_in_seconds); + void SpawnFood(); + + void Draw(RenderGroup &render_group); + void DoImgui(); + + + +private: + static constexpr int32_t MAX_MAP_WIDTH = 16; + static constexpr int32_t MAX_MAP_HEIGHT = 16; + + bool m_IsPaused; + bool m_IsRunning; + + float m_DtInSecondsRemaining; + uint64_t m_LastMillisecondsSinceT0; + + float m_TilesPerSecond; + Direction m_Direction; + Direction m_LastAdvancedDirection; + + int32_t m_MapWidth; + int32_t m_MapHeight; + int32_t m_Tail; + int32_t m_Head; + uint64_t m_BodyBitmap[MAX_MAP_HEIGHT]; + V2I32 m_BodyPositions[MAX_MAP_WIDTH * MAX_MAP_HEIGHT]; + V2I32 m_FoodPosition; + + std::mt19937 m_Rng; + std::uniform_int_distribution<int32_t> m_Dist; +}; + + |