-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock.cpp
More file actions
45 lines (39 loc) · 1.12 KB
/
Copy pathblock.cpp
File metadata and controls
45 lines (39 loc) · 1.12 KB
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
#include "block.h"
Block::Block() {
cellSize = 30;
rotationState = 0;
colors = GetCellColors();
rowOffset = 0;
columnOffset = 0;
}
void Block::Draw(int offsetX, int offsetY) {
std::vector<Position> tiles = GetCellPositions();
for(Position item: tiles) {
DrawRectangle(item.column * cellSize + offsetX, item.row * cellSize + offsetY, cellSize - 1, cellSize - 1, colors[id]);
}
}
void Block::Move(int rows, int columns) {
rowOffset += rows;
columnOffset += columns;
}
std::vector<Position> Block::GetCellPositions() {
std::vector<Position> tiles = cells[rotationState];
std::vector<Position> movedTiles;
for(Position item: tiles) {
Position newPos = Position(item.row + rowOffset, item.column + columnOffset);
movedTiles.push_back(newPos);
}
return movedTiles;
}
void Block::Rotate() {
rotationState++;
if(rotationState == (int)cells.size()) {
rotationState = 0;
}
}
void Block::UndoRotation() {
rotationState--;
if(rotationState == -1) {
rotationState = cells.size() - 1;
}
}