SnakeGame
This commit is contained in:
31
blockade/Snake.h
Normal file
31
blockade/Snake.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user