diff options
author | Oxore <oxore@protonmail.com> | 2018-06-25 15:50:58 +0300 |
---|---|---|
committer | Oxore <oxore@protonmail.com> | 2018-06-25 15:50:58 +0300 |
commit | bf0e5690a31d4c3cecd2ba512729a0b73989bbda (patch) | |
tree | 5b95c5a52c8a9025593231ee0285d81d40890f0f /include/field.h | |
parent | 63e929f7a23b44ff2b1e33ccf16307de20c2bdc8 (diff) |
Major refactoring
Fix memleak in KeyMap, fix memleak caused by loading a yaml file in
main.c. Change Copyright information. Rename functions.c and .h to
engine.c and .h. Take field and shape related functions to separate file
(still not all of them) and refactor them a lot. Refactor collision
detection. Add more warnings. Add sanitizer option commented out.
Diffstat (limited to 'include/field.h')
-rw-r--r-- | include/field.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/include/field.h b/include/field.h new file mode 100644 index 0000000..410e609 --- /dev/null +++ b/include/field.h @@ -0,0 +1,58 @@ +#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 +/* + * Types + * + * */ + +struct cell { + char a; // active/empty state of cell + sfColor fColor; // fill color +}; + + +/* + * shape coords + * y + * ^. . . . + * |. . . . + * |. . . . + * |. . . . + * 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 init_next_shape_field(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); |