-
Notifications
You must be signed in to change notification settings - Fork 2
/
shapes.h
118 lines (100 loc) · 2.08 KB
/
shapes.h
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
#ifndef SHAPES_H
#define SHAPES_H
#include "utils.h"
#define SHAPE_BOUNDS_WIDTH 4
#define SHAPE_BOUNDS_HEIGHT 4
#define SHAPE_SIZE (SHAPE_BOUNDS_HEIGHT * SHAPE_BOUNDS_WIDTH)
#define AT(x, y) (SHAPE_BOUNDS_WIDTH * y + x)
struct tetromino_t {
unsigned int width;
unsigned int height;
int shape_data[SHAPE_SIZE];
int at(unsigned int x, unsigned int y) {
if (x >= width) return 0;
if (y >= height) return 0;
return shape_data[AT(x, y)];
}
// returns rotated position offset
point_t rotated_shape_data(const int rotation, int (*result_shape_data)[16]);
};
static tetromino_t SquareBlock = {
.width = 2,
.height = 2,
.shape_data = {
1, 1, 0, 0,
1, 1, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
},
};
static tetromino_t LeftLBlock = {
.width = 2,
.height = 3,
.shape_data = {
1, 0, 0, 0,
1, 0, 0, 0,
1, 1, 0, 0,
0, 0, 0, 0,
},
};
static tetromino_t RightLBlock = {
.width = 2,
.height = 3,
.shape_data = {
0, 1, 0, 0,
0, 1, 0, 0,
1, 1, 0, 0,
0, 0, 0, 0,
},
};
static tetromino_t LongBlock = {
.width = 1,
.height = 4,
.shape_data = {
1, 0, 0, 0,
1, 0, 0, 0,
1, 0, 0, 0,
1, 0, 0, 0,
},
};
static tetromino_t MountainBlock = {
.width = 3,
.height = 2,
.shape_data = {
0, 1, 0, 0,
1, 1, 1, 0,
0, 0, 0, 0,
0, 0, 0, 0,
},
};
static tetromino_t ZBlock = {
.width = 3,
.height = 2,
.shape_data = {
1, 1, 0, 0,
0, 1, 1, 0,
0, 0, 0, 0,
0, 0, 0, 0,
},
};
static tetromino_t SBlock = {
.width = 3,
.height = 2,
.shape_data = {
0, 1, 1, 0,
1, 1, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
},
};
struct shape_actor_t
{
public:
point_t position;
tetromino_t *tetromino;
int rotation = 0;
shape_actor_t() {};
shape_actor_t(const shape_actor_t& a)
: position(a.position), tetromino(a.tetromino), rotation(a.rotation) {};
};
#endif