-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathPlayer.hpp
71 lines (51 loc) · 1.07 KB
/
Player.hpp
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
65
66
67
68
69
70
#ifndef PLAYER_H_DEFINED
#define PLAYER_H_DEFINED
#include <Engine/Graphics/Window.hpp>
#include <vector>
struct Body
{
int x;
int y;
Body(int x, int y):
x(x),
y(y)
{ }
};
// Avoiding circular #include hell.
class Board;
///
class Player
{
public:
enum Direction
{
UP, DOWN, LEFT, RIGHT
};
Player(int x, int y);
virtual ~Player() { };
bool isAlive();
int getSize();
int getDirection();
int getX(); ///< Returns the head's x position.
int getY(); ///< Returns the head's y position.
void moveTo(int x, int y);
void move(Direction direction);
void kill();
void update(Board* board);
void draw(Window* win);
bool headHit(int x, int y);
/// Tells if something at #x and #y collides with
/// any part of the snake.
///
/// @note #isHead is a huge HACK to allow me to
/// check if the head collides with the body.
/// Ignore it.
bool bodyHit(int x, int y, bool isCheckingHead=false);
void increase();
private:
std::vector<Body> body;
bool alive;
Direction currentDirection;
Direction nextDirection;
};
#endif //PLAYER_H_DEFINED