#pragma once #include #include #include class Snake : public Game { public: enum Direction : int32_t { up, down, left, right, }; public: Snake(); bool Update(std::vector& events) override; private: 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(); private: 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 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; };