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
|
#include "piece.h"
Piece::Piece(Piece::PieceType type, int xpos){
switch (type){
case PieceType::LINE:
blocks[0] = { 1, 0 };
blocks[1] = { 1, 1 };
blocks[2] = { 1, 2 };
blocks[3] = { 1, 3 };
break;
case PieceType::BLOCK:
blocks[0] = { 1, 1 };
blocks[1] = { 1, 2 };
blocks[2] = { 2, 1 };
blocks[3] = { 2, 2 };
break;
case PieceType::S:
blocks[0] = { 1, 0 };
blocks[1] = { 1, 1 };
blocks[2] = { 1, 2 };
blocks[3] = { 1, 3 };
break;
case PieceType::T:
blocks[0] = { 1, 0 };
blocks[1] = { 1, 1 };
blocks[2] = { 1, 2 };
blocks[3] = { 1, 3 };
break;
case PieceType::L:
blocks[0] = { 1, 0 };
blocks[1] = { 1, 1 };
blocks[2] = { 1, 2 };
blocks[3] = { 1, 3 };
break;
}
position_ = {xpos, 0};
}
void Piece::initIterator(){
iterator = 0;
}
Point* Piece::nextAbsBlockPos(){
current_block_ = blocks[iterator++];
current_block_.x += position_.x;
current_block_.y += position_.y;
if( iterator > SIZE ){
iterator = 0;
return nullptr;
}
return ¤t_block_;
}
void Piece::rotate(){
int tmp;
// FLIP
for( int i = 0; i < SIZE; i++ ){
tmp = blocks[i].y;
blocks[i].y = blocks[i].x;
blocks[i].x = tmp;
}
// MIRROR
for( int i = 0; i < SIZE; i++ ){
blocks[i].x = blocks[i].x * (-1) + (SIZE-1);
}
}
void Piece::advance(){
position_.y++;
}
void Piece::move_left(){
position_.x--;
}
void Piece::move_right(){
position_.x++;
}
|