More cleaning for readabillity, added common file
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
#include <SFML\Graphics.hpp>
|
||||
|
||||
const int kGridSize = 25;
|
||||
|
||||
enum PlayerDirection
|
||||
{
|
||||
kLeft = 1,
|
||||
kUp = 2,
|
||||
kDown = 3,
|
||||
kRight = 4
|
||||
};
|
||||
|
||||
bool GlobalCollision(sf::Vector2f object1Position, sf::Vector2f object2Position);
|
||||
|
||||
#endif
|
||||
+1
-4
@@ -12,10 +12,6 @@ public:
|
||||
GameState(int newHorizontal, int newVertical);
|
||||
void StartGame(void);
|
||||
sf::Vector2f GetGameBoundaries(void);
|
||||
/*
|
||||
gameGridHorizontal = (videoSizeHorizontal // 25) * 25;
|
||||
gameGridVertical = (videoSizeVertical // 25) * 25;
|
||||
*/
|
||||
protected:
|
||||
;
|
||||
private:
|
||||
@@ -24,6 +20,7 @@ private:
|
||||
SnakeFood playerFood;
|
||||
Snake player;
|
||||
sf::Time delay;
|
||||
void GetKeyboardInput(void);
|
||||
void RegenerateFood(void);
|
||||
void RunGameLoop(void);
|
||||
void RenderWindow(void);
|
||||
|
||||
+8
-9
@@ -6,27 +6,26 @@
|
||||
#include <SFML\Graphics.hpp>
|
||||
#include "SnakeFood.h"
|
||||
|
||||
sf::Vector2f CalculateNewPosition(int direction, sf::Vector2f position);
|
||||
bool GlobalCollision(sf::Vector2f object1Position, sf::Vector2f object2Position);
|
||||
|
||||
class Snake
|
||||
{
|
||||
public:
|
||||
Snake();
|
||||
Snake(void);
|
||||
Snake(sf::Vector2f head);
|
||||
sf::Vector2f GetSnakeHeadPosition();
|
||||
sf::RectangleShape GetSnakeHead();
|
||||
void DisplaySnake(sf::RenderWindow& window);
|
||||
void MoveSnake(SnakeFood& playerFood, sf::VideoMode gameVideoMode);
|
||||
void CheckDirection();
|
||||
bool CheckBoundaries();
|
||||
bool IsSelfCollision(sf::RectangleShape testRectangle);
|
||||
sf::RectangleShape GetSnakeHead(void);
|
||||
sf::Vector2f GetSnakeHeadPosition(void);
|
||||
bool IsTouchingObject(sf::RectangleShape object);
|
||||
void MoveSnake(SnakeFood* playerFood);
|
||||
void UpdateDirection(int newDirection);
|
||||
protected:
|
||||
;
|
||||
private:
|
||||
std::deque<sf::RectangleShape> snakeBody;
|
||||
int snakeDirection = 0;
|
||||
sf::Vector2f CalculateNewPosition(sf::Vector2f position);
|
||||
bool CheckBoundaries(void);
|
||||
bool IsSelfCollision(sf::RectangleShape testRectangle);
|
||||
};
|
||||
|
||||
|
||||
|
||||
+2
-3
@@ -2,10 +2,8 @@
|
||||
#ifndef SNAKEFOOD_H
|
||||
#define SNAKEFOOD_H
|
||||
|
||||
#include <random>
|
||||
#include <SFML\Graphics.hpp>
|
||||
|
||||
extern const int kGridSize;
|
||||
#include <random>
|
||||
|
||||
class SnakeFood
|
||||
{
|
||||
@@ -14,6 +12,7 @@ public:
|
||||
SnakeFood(sf::Vector2f snakeFoodSize);
|
||||
void GenerateNewFood(sf::Vector2f windowSize);
|
||||
sf::RectangleShape GetFoodObject(void);
|
||||
sf::Vector2f GetFoodObjectPosition(void);
|
||||
protected:
|
||||
;
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user