Files
HuajisheTools/Huajisheblockade/Snake.h
2025-12-31 13:22:56 +08:00

32 lines
807 B
C++

#ifndef SNAKE_H_
#define SNAKE_H_
#include "SDL3/SDL_rect.h"
#include <deque>
#include <SDL3/SDL.h>
#include <random>
#include <ctime>
class Snake {
public:
Snake(int screenWidth, int screenHeight, int segmentSize);
void HandleInput(SDL_Keycode key);
void Update();
void Render(SDL_Renderer* renderer);
void Grow();
void Reset(int screenWidth, int screenHeight);
void RandomizeDirection();
bool CheckCollision(int screenWidth, int screenHeight);
SDL_Point GetHeadPos() const;
std::deque<SDL_Point> GetBody() const;
private:
// Using SDL_Point to store {x, y} coordinates
std::deque<SDL_Point> body;
SDL_Point direction;
int segmentSize; // Size of each block in pixels
bool growing = false; // Flag to skip pop_back when eating food
};
#endif