-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPiece.cpp
136 lines (119 loc) · 2.08 KB
/
Piece.cpp
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "Piece.hpp"
Piece::Piece(const bool white)
{
_X = 0;
_Y = 0;
_XWindow = 0;
_YWindow = 0;
_IsAlive = true;
_IsWhite = white;
_IsDragged = false;
}
/**
* Changes the state of a piece if it's dragged or not
* @param isDragged is the piece dragged or no
*/
void Piece::setIsDragged(const bool dragged)
{
if(dragged)
_IsDragged = true;
else
_IsDragged = false;
}
/**
* Get the state of a piece if it's dragged or not
* @return isDragged is the piece dragged or no
*/
bool Piece::getIsDragged() const
{
return _IsDragged;
}
/**
* Changes the position of the piece on the board
* @param to Vector of new coordinate on the board
*/
void Piece::moveBoard(const Vector2i to)
{
_X = to.x;
_Y = to.y;
Vector2i toWindow = (to + Vector2i(1, 1));
toWindow = toWindow * 55;
moveWindow(Vector2f(toWindow));
}
/**
* Changes the position of the piece on the window
* @param to Vector of new coordinate on the window (in pixels)
*/
void Piece::moveWindow(const Vector2f to)
{
_XWindow = to.x;
_YWindow = to.y;
_PieceSprite.setPosition(_XWindow, _YWindow);
}
/**
* Indicates if the piece is still alive
* @returns true if the piece is alive, else false
*/
bool Piece::isAlive() const
{
return _IsAlive;
}
/**
* Kills the piece
*/
void Piece::kill()
{
_IsAlive = false;
moveWindow(Vector2f(9999,9999));
}
/**
* Revives the piece
*/
void Piece::revive()
{
_IsAlive = true;
moveWindow(Vector2f((_X + 1)*55,(_Y + 1)*55));
}
/**
* Gets X
* @returns X coordinate
*/
int Piece::getX() const
{
return _X;
}
/**
* Gets Y
* @returns Y coordinate
*/
int Piece::getY() const
{
return _Y;
}
/**
* Gets X
* @returns X coordinate
*/
int Piece::getXWindow() const
{
return _XWindow;
}
/**
* Gets Y
* @returns Y coordinate
*/
int Piece::getYWindow() const
{
return _YWindow;
}
/**
* Returns a pointer to the sprite
* @returns A pointer to the Piece's sprite
*/
Sprite* Piece::getSprite()
{
return &_PieceSprite;
}
Piece::~Piece()
{
}