aboutsummaryrefslogtreecommitdiff
path: root/src/games/snake/Snake.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/games/snake/Snake.hpp')
-rw-r--r--src/games/snake/Snake.hpp50
1 files changed, 22 insertions, 28 deletions
diff --git a/src/games/snake/Snake.hpp b/src/games/snake/Snake.hpp
index 51d98fb..103255c 100644
--- a/src/games/snake/Snake.hpp
+++ b/src/games/snake/Snake.hpp
@@ -18,45 +18,39 @@ public:
public:
Snake();
- bool Update(std::vector<SDL_Event> &events) override;
+ bool Update(std::vector<SDL_Event>& events) override;
private:
- void ProcessEventDuringPause(SDL_Event &event);
- void ProcessEventDuringResume(SDL_Event &event);
+ void ProcessEventDuringPause(SDL_Event& event);
+ void ProcessEventDuringResume(SDL_Event& event);
+
+ void Start(int32_t map_width, int32_t map_height);
void MaybeMoveSnake(float dt_in_seconds);
void SpawnFood();
void Draw();
- 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;
+ static constexpr int32_t max_map_width = 16;
+ static constexpr int32_t max_map_height = 16;
+ static constexpr float tiles_per_second = 4.0f;
+
+ static std::mt19937 s_rng;
+ std::uniform_int_distribution<int32_t> m_dist;
+
+ Direction m_direction;
+ Direction m_last_advanced_direction;
+
+ int32_t m_map_width;
+ int32_t m_map_height;
+ int32_t m_tail {0};
+ int32_t m_head {1};
+ uint64_t m_body_bitmap[max_map_height];
+ V2I32 m_body_positions[max_map_width * max_map_height];
+ V2I32 m_food_position;
};