diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/common.h | 77 | ||||
-rw-r--r-- | include/engine.h | 19 | ||||
-rw-r--r-- | include/field.h | 58 | ||||
-rw-r--r-- | include/functions.h | 34 | ||||
-rw-r--r-- | include/text.h | 48 |
5 files changed, 116 insertions, 120 deletions
diff --git a/include/common.h b/include/common.h index 773cb3f..275547a 100644 --- a/include/common.h +++ b/include/common.h @@ -1,82 +1,13 @@ -/* - * Types - * - * */ - -typedef struct Cell { - char a; // active/empty state of cell - sfColor fColor; // fill color -} Cell; - - -/* - * shape coords - * y - * ^. . . . - * |. . . . - * |. . . . - * |. . . . - * 0------->x - * - */ - -typedef 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 - sfVector2f cSize; // shape rectangles size variable x/y -} Shape; - -typedef struct Field { - sfVector2i pos; - sfColor fColor; // shape color - Cell c[25][10]; // array of logic shape cells - sfRectangleShape *p[25][10]; // array of physical shape cells - int cOutThick; // Field rectangles outline thickness - sfVector2f cSize; // shape rectangles size variable x/y - sfVector2i size; -} Field; - -typedef struct Window { +struct window { sfVideoMode mode; sfRenderWindow *window; sfEvent event; -} Window; +}; -typedef struct Game { +struct game { int isStarted; int scoreCurrent; int level; int moveLatency; int lines; -} Game; - -/* ======== text.[c|h] types =========== */ - -typedef struct List { - void *obj; - void *next; - void *prev; -} List; - -typedef struct Pair { - void *k; - void *v; -} Pair; - -typedef struct KeyMap { - Pair *pair; - void *next; - void *prev; -} KeyMap; - -typedef struct Text { - char *font; - char *type; - char *scene; - char *text; - void *sfText; -} Text; +}; diff --git a/include/engine.h b/include/engine.h new file mode 100644 index 0000000..655eb01 --- /dev/null +++ b/include/engine.h @@ -0,0 +1,19 @@ +#define RIGHT 1 +#define DOWN 2 +#define UP 4 +#define LEFT 8 +#define RIGHTHOLD 16 +#define LEFTHOLD 128 + +void tKeyCtrl(); +void tTick(); +void checkLevelUp(struct game *game); +int getMoveLatencyOfLevel(int level); +int rmLines(); +void valueAfterTextDisplay(int value, List *texts, char *type); +void colorizeActive(); +void drawFld(sfRenderWindow *window); +void gameover(struct game *game); +void genNextShape(); +void drawNextShape(); +void freeFld(); 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); diff --git a/include/functions.h b/include/functions.h deleted file mode 100644 index f47f816..0000000 --- a/include/functions.h +++ /dev/null @@ -1,34 +0,0 @@ -#define RIGHT 0b0001 -#define DOWN 0b0010 -#define UP 0b0100 -#define LEFT 0b1000 -#define RIGHTHOLD 0b10000 -#define LEFTHOLD 0b10000000 - -void tKeyCtrl(); -void initFld(); -void tTick(); -void resetActiveShape(Shape *active); -void putShape(); -int outOfFieldCheck(Field *fld, Shape *active); -void checkLevelUp(Game *game); -int getMoveLatencyOfLevel(int level); -int cellCollisionCheckHere(Field *fld, Shape *active); -int cellCollisionCheck(int dir); -int wallCollisionCheck(); -int cellRotCollisionCheck(); -int wallRotCollisionCheck(); -void rotateLeft(); -void rotateRight(); -void rotateShape(); -int rmLines(); -void valueAfterTextDisplay(int value, List *texts, char *type); -void colorizeFld(); -void colorizeActive(); -void drawFld(sfRenderWindow *window); -void colorizeRandom(Field *fld); -void gameover(Game *game); -void genNextShape(); -void copyShape(Shape *localSh); -void drawNextShape(); -void freeFld(); diff --git a/include/text.h b/include/text.h index 1171a51..73285bf 100644 --- a/include/text.h +++ b/include/text.h @@ -1,17 +1,39 @@ -FILE *openFile(char *filename); -void checkArgs(int argc, char **argv); +typedef struct List { + void *obj; + void *next; + void *prev; +} List; + +typedef struct Pair { + void *k; + void *v; +} Pair; + +typedef struct KeyMap { + Pair *pair; + void *next; + void *prev; +} KeyMap; + +typedef struct Text { + char *font; + char *type; + char *scene; + char *text; + void *sfText; +} Text; + +FILE *openFile(char *filename); +void checkArgs(int argc, char **argv); KeyMap *KeyMap_getLast(KeyMap **keyMap); KeyMap *KeyMap_new(KeyMap **keyMap); KeyMap *KeyMap_get(KeyMap **keyMap, const void *key); KeyMap *KeyMap_put(KeyMap **keyMap, const void *key, const void *value); -List *List_getLast(List **list); -List *List_new(List **list); -List *ListOfKeyMapOfString_getFromYaml(char *filename); -void KeyMapOfString_free(KeyMap *keyMap); -void ListOfKeyMapOfString_free(List **list); -int _loadText_getInt(void *obj, char *key); -char *_loadText_getString(void *obj, char *key); -void _loadText_initSfText(Text *objo, void *obji); -List *ListOfText_getFromListOfKeyMapOfString(List *list); -void Text_free(Text *obj); -void ListOfText_free(List **list); +List *List_getLast(List **list); +List *List_new(List **list); +List *ListOfKeyMapOfString_getFromYaml(char *filename); +void KeyMapOfString_free(KeyMap *keyMap); +void ListOfKeyMapOfString_free(List **list); +List *ListOfText_getFromListOfKeyMapOfString(List *list); +void Text_free(Text *obj); +void ListOfText_free(List **list); |