-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblocks.c
73 lines (62 loc) · 1.15 KB
/
blocks.c
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
#include "blocks.h"
tetromino_template const tetro_i = {
{
1, 1, 1, 1,
0, 0, 0, 0
}
};
tetromino_template const tetro_o = {
{
0, 1, 1, 0,
0, 1, 1, 0
}
};
tetromino_template const tetro_t = {
{
1, 1, 1, 0,
0, 1, 0, 0
}
};
tetromino_template const tetro_s = {
{
0, 1, 1, 0,
1, 1, 0, 0
}
};
tetromino_template const tetro_z = {
{
1, 1, 0, 0,
0, 1, 1, 0
}
};
tetromino_template const tetro_j = {
{
1, 1, 1, 0,
1, 0, 0, 0
}
};
tetromino_template const tetro_l = {
{
1, 1, 1, 0,
0, 0, 1, 0
}
};
tetromino_template const * const TETROMINOES[TETROMINO_COUNT] = {
&tetro_i,
&tetro_o,
&tetro_t,
&tetro_s,
&tetro_z,
&tetro_j,
&tetro_l
};
vec2 const PIVOT_OFFSET = { .x = 1, .y = 0 };
vec2 tetro_index_to_tetro_local(UINT8 index) {
// p is the column-row representation (origin in top-left corner)
vec2 p = { index % TETROMINO_WIDTH, index / TETROMINO_WIDTH };
// convert to pivot at origin
return vec2_add(p, vec2_flip(PIVOT_OFFSET));
}
vec2 tetro_local_to_grid_local(tetromino const * const t, vec2 pos) {
return vec2_add(t->position, apply_rotation(t->rotation, pos));
}