Game finishes, but is buggy. Proper grid needed

This commit is contained in:
2023-03-13 08:24:56 -05:00
parent 6589dabc09
commit 3ee01d936b
4 changed files with 79 additions and 18 deletions
+2
View File
@@ -20,7 +20,9 @@ private:
SnakeFood playerFood;
Snake player;
sf::Time delay;
void DisplayEndScreen(void);
void GetKeyboardInput(void);
bool PlayerWantsToContinue(void);
void RegenerateFood(void);
void RunGameLoop(void);
void RenderWindow(void);
+5 -1
View File
@@ -10,21 +10,25 @@
class Snake
{
public:
bool gameFinished = false;
Snake(void);
Snake(sf::Vector2f head);
void DisplaySnake(sf::RenderWindow& window);
sf::RectangleShape GetSnakeHead(void);
sf::Vector2f GetSnakeHeadPosition(void);
bool IsTouchingObject(sf::RectangleShape object);
void MoveSnake(SnakeFood* playerFood);
void Reset(void);
void UpdateDirection(int newDirection);
protected:
;
private:
std::deque<sf::RectangleShape> snakeBody;
sf::Vector2f bodyPartSize;
int snakeDirection = 0;
void AddBodyPart(sf::RectangleShape newBodyPart);
sf::Vector2f CalculateNewPosition(sf::Vector2f position);
bool CheckBoundaries(void);
void CreateHead(void);
bool IsSelfCollision(sf::RectangleShape testRectangle);
};