-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpiece.cpp
More file actions
47 lines (38 loc) · 890 Bytes
/
Copy pathpiece.cpp
File metadata and controls
47 lines (38 loc) · 890 Bytes
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
#include "piece.h"
#include "textureManager.h"
Piece::Piece(const char* filename, SDL_Renderer* ren, int bRow, int bColumn, char c)
{
renderer = ren;
objectTexture = TextureManager::LoadTexture(filename, ren);
boardRow = bRow;
boardColumn = bColumn;
color = c;
}
Piece::~Piece() {}
void Piece::calculateXY()
{
xPosition = boardColumn * PIECES_X_DISTANCE - 38;
yPosition = 35 - 67 + boardRow * PIECES_Y_DISTANCE;
}
void Piece::update()
{
calculateXY();
sourceRect.h = PIECE_HEIGHT;
sourceRect.w = PIECE_WIDTH;
sourceRect.x = 0;
sourceRect.y = 0;
destinationRect.x = xPosition;
destinationRect.y = yPosition;
destinationRect.w = sourceRect.w;
destinationRect.h = sourceRect.h;
}
void Piece::render()
{
SDL_RenderCopy(renderer, objectTexture, &sourceRect, &destinationRect);
}
int Piece::absoluteValue(int a, int b)
{
if (a - b < 0)
return b - a;
return a - b;
}