From b46a0d9369fbaa1938f0968ab216bc2d564a9c37 Mon Sep 17 00:00:00 2001 From: fschildt Date: Mon, 21 Jul 2025 16:07:28 +0200 Subject: first commit --- src/games/snake/Snake.hpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/games/snake/Snake.hpp (limited to 'src/games/snake/Snake.hpp') 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 +#include + +#include + + +class Snake : public Game { +public: + enum Direction : int32_t { + DIRECTION_UP, + DIRECTION_DOWN, + DIRECTION_LEFT, + DIRECTION_RIGHT, + }; + + +public: + Snake(); + bool Update(std::vector &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 m_Dist; +}; + + -- cgit v1.2.3