Retro_Gameboy
The purpose of this project is to create a GameBoy with classic games.
Snake.h
Go to the documentation of this file.
1 #ifndef SNAKE_H
2 #define SNAKE_H
3 
4 #include "GameGenerics.h"
5 
6 class Snake : public GameGenerics
7 {
8 
9  private:
10 
12  const int N = 30;
13 
15  const int M = 20;
16 
18  const int SIZE = 16;
19 
21  const int WIDTH = SIZE * N;
22 
24  const int HEIGHT = SIZE * M;
25 
28 
31 
33  int m_Score;
34 
37 
40  struct SnakeStrct
41  {
42  int x;
43  int y;
44  };
45 
47  struct Fruit
48  {
49  int x;
50  int y;
51  };
52 
56 
59 
65  void InitializeVars();
66 
68  void MoveSnake();
69 
75  void MoveToThisDirection();
76 
79  void BoundaryControl();
80 
82  void GrowUponEat();
83 
85  void KeyControls();
86 
88  void DrawSprites( RenderWindow& window, Sprite& sprite1, Sprite& sprite2 );
89 
91  void GameOverLogic();
92 
94  void PlaySnake( RenderWindow& window, Sprite& sprite1, Sprite& sprite2 );
95 
96 
97  public:
98 
101  Snake();
102 
105  virtual int CalculateScore();
106 
107 
108 };
109 #endif // SNAKE_H
Definition: Snake.h:7
int m_direction
Direction of the snake.
Definition: Snake.h:27
const int WIDTH
Define width of the window.
Definition: Snake.h:21
virtual int CalculateScore()
Pure virtual function inherited from GameGenerics.h Each game calculate scores differently and theref...
Definition: Snake.cpp:27
int m_Score
Track game score.
Definition: Snake.h:33
void MoveSnake()
Move Snake across the grid per Tick.
Definition: Snake.cpp:33
const int N
Define length with 30 squares.
Definition: Snake.h:12
void PlaySnake(RenderWindow &window, Sprite &sprite1, Sprite &sprite2)
Start the game.
Definition: Snake.cpp:165
void GameOverLogic()
Whenever snake tries to eat itself game is over.
Definition: Snake.cpp:48
void KeyControls()
Allow user to control snake by using arrow keys.
Definition: Snake.cpp:116
void BoundaryControl()
If snake cross the boundary of the window make it reappear on the opposite side of the window.
Definition: Snake.cpp:70
SnakeStrct m_MySnake[100]
Holds x and y cordinates of the fruit.
Definition: Snake.h:58
void InitializeVars()
Create Sprites. Load the Images and set the Sprites. Call PlaySnake() function to start the game.
Definition: Snake.cpp:8
int m_SnakeLength
Length of the snake.
Definition: Snake.h:30
void MoveToThisDirection()
Set the direction to move the snake. 0 indicates down. 3 indicates up. 1 indicates left....
Definition: Snake.cpp:93
Snake()
Default Constructor. initialize variables.
Definition: Snake.cpp:3
const int HEIGHT
Define height of the window.
Definition: Snake.h:24
void GrowUponEat()
Whenever snake eats a fruit make it grow by 1 square.
Definition: Snake.cpp:59
const int SIZE
Define space between each square.
Definition: Snake.h:18
void DrawSprites(RenderWindow &window, Sprite &sprite1, Sprite &sprite2)
Draw sprites on the window.
Definition: Snake.cpp:139
bool m_IsGameOver
Track when game is over or not.
Definition: Snake.h:36
Fruit m_MyFruit
Holds x and y cordinates of the snake when it move across the grid.
Definition: Snake.h:55
const int M
Define height with 30 squares.
Definition: Snake.h:15
Structure to holds x and y cordinates of the fruit.
Definition: Snake.h:48
int y
Definition: Snake.h:50
int x
Definition: Snake.h:49
Structure to holds x and y cordinates of the snake when it move across the grid.
Definition: Snake.h:41