summaryrefslogtreecommitdiff
path: root/include/field.h
blob: 6e1c92842bb0bb99b3fa3ba6e35a6d755aea5e3d (plain)
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
#define FLD_SIZE_Y   22
#define FLD_SIZE_X   10
#define FLD_BOUND_Y FLD_SIZE_Y + 3
#define FLD_BOUND_X FLD_SIZE_X

struct cell {
    char a; // active/empty state of cell
    sfColor fColor; // fill color
};


/*
 * field + shape coord system
 * y
 * ^. . . . . . .
 * |. . . . . . .
 * |. . . . . . .
 * |. . y . . . .
 * |. . ^ . . . .
 * |. . | . . . .
 * |. . | . . . .
 * |. . 0------>x
 * |. . . . . . .
 * |. . . . . . .
 * 0------------->x
 *
 */

struct shape {
    int x; // x coord of shape's left side
    int y; // y coord of shape's bottom
    int t; // shape type
    sfColor fColor; // shape color
    char c[4][4]; // array of logic shape cells
    sfRectangleShape *p[4][4]; // array of physical shape cells
    int cOutThick; // shape rectangles outline thickness
    sfVector2f cSize; // shape rectangles size variable x/y
};

struct field {
    sfVector2i pos;
    sfColor fColor; // shape color
    struct cell c[FLD_BOUND_Y][FLD_SIZE_X]; // array of logic shape cells
    sfRectangleShape *p[FLD_BOUND_Y][FLD_SIZE_X]; // array of physical shape cells
    int cOutThick; // Field rectangles outline thickness
    sfVector2f cSize; // shape rectangles size variable x/y
    sfVector2i size;
    sfVector2i bound;
};

void init_field(struct field *fld);
void colorize_field(struct field *fld);
void colorize_field_random(struct field *fld);
void colorize_active_shape(struct field *fld, struct shape *shape);
void init_next_shape(struct shape *next);
void putShape(struct field *fld, struct shape *active);
int  out_of_field(struct field *fld, struct shape *active);
void load_shape(struct shape *shape);
void rotate_shape(struct field *fld, struct shape *shape);
int  collide(struct field *fld, struct shape *active);
void resetActiveShape(struct field *fld, struct shape *active);
void gen_shape(struct shape *shape);
int  rm_lines(struct field *fld);
void free_field(struct field *fld);
void free_shape(struct shape *shape);