-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnakeGame.h
64 lines (48 loc) · 946 Bytes
/
SnakeGame.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef SNAKEGAME_H
#define SNAKEGAME_H
#include "Game.h"
class SnakeGame : public Game
{
public:
SnakeGame(const std::string& title, int width, int height);
virtual ~SnakeGame();
virtual void OnInit() override;
virtual void OnUpdate() override;
virtual void OnDraw(Window& window) override;
virtual void OnHandleInput();
private:
void Tick();
void Reset();
private:
sf::Texture textureRed;
sf::Texture textureWhite;
sf::Texture textureGreen;
sf::Sprite spriteBackground;
sf::Sprite spriteSnake;
sf::Sprite spriteApple;
sf::Clock clock;
float timer;
static const int SEGMENT_MAX = 100;
int nSegments;
enum class etDirection
{
eNONE,
eUP,
eDOWN,
eRIGHT,
eLEFT
}
direction;
struct SnakeSegment
{
int x;
int y;
bool operator==(const SnakeSegment& other) const
{
return (x == other.x && y == other.y);
}
}
snakePos[SnakeGame::SEGMENT_MAX] = {-1, -1};
SnakeSegment applePos;
};
#endif