summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2018-07-02 23:11:26 +0300
committerOxore <oxore@protonmail.com>2018-07-02 23:11:26 +0300
commit21a0a44853451f3d791bafc80c01deab0ff4c79e (patch)
tree7636e99380c570d903db114ad2834f8bbd93fd7b /include
parentbb9d1873ad414b09efdd7c8bf6798b431adb3cb2 (diff)
Introduce draw manager, refactor main
Move timers to struct game. Partially move field painting to draw manager.
Diffstat (limited to 'include')
-rw-r--r--include/common.h22
-rw-r--r--include/draw.h23
-rw-r--r--include/engine.h2
-rw-r--r--include/field.h12
-rw-r--r--include/tet_conf.h4
5 files changed, 47 insertions, 16 deletions
diff --git a/include/common.h b/include/common.h
index 275547a..7a85dbc 100644
--- a/include/common.h
+++ b/include/common.h
@@ -1,13 +1,13 @@
-struct window {
- sfVideoMode mode;
- sfRenderWindow *window;
- sfEvent event;
-};
-
struct game {
- int isStarted;
- int scoreCurrent;
- int level;
- int moveLatency;
- int lines;
+ int isStarted;
+ int scoreCurrent;
+ int level;
+ int moveLatency;
+ int lines;
+ sfClock *gameTick;
+ sfClock *putTick;
+ sfClock *mTick;
+ sfClock *repPushDown; // Clock for repeat latency when Down arrow long push
+ sfClock *repKeyLeft; // Clock for repeat latency when Left arrow long push
+ sfClock *repKeyRight; // Clock for repeat latency when Left arrow long push
};
diff --git a/include/draw.h b/include/draw.h
new file mode 100644
index 0000000..3408142
--- /dev/null
+++ b/include/draw.h
@@ -0,0 +1,23 @@
+struct window {
+ sfVideoMode mode;
+ sfRenderWindow *window;
+ sfEvent event;
+};
+
+//struct field_conf {
+// sfVector2i pos;
+// int cOutThick;
+// sfVector2f cSize;
+// sfVector2i size;
+//} field_conf;
+
+void painter_init_window();
+
+unsigned long painter_register_field();
+void painter_update_field(unsigned long id, struct field *fld);
+
+unsigned long painter_register_shape();
+void painter_update_shape(unsigned long id, struct shape *shape);
+
+void painter_draw();
+void painter_destroy_window();
diff --git a/include/engine.h b/include/engine.h
index 7a4ce32..2dd7e9f 100644
--- a/include/engine.h
+++ b/include/engine.h
@@ -10,6 +10,6 @@ void tTick();
void checkLevelUp(struct game *game);
int getMoveLatencyOfLevel(int level);
void valueAfterTextDisplay(int value, List *texts, char *type);
-void drawFld(sfRenderWindow *window);
+void drawFld(sfRenderWindow *window, struct field *fld);
void gameover(struct game *game);
void drawNextShape(sfRenderWindow *window);
diff --git a/include/field.h b/include/field.h
index 6e1c928..f037d41 100644
--- a/include/field.h
+++ b/include/field.h
@@ -1,11 +1,15 @@
-#define FLD_SIZE_Y 22
-#define FLD_SIZE_X 10
+#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
+#define FLD_POS (sfVector2i){.x = 10, .y = 10+550-24}
+#define FLD_SIZE (sfVector2f){.x = FLD_SIZE_X, .y = FLD_SIZE_Y}
+#define CELL_SIZE (sfVector2f){.x = 23, .y = 23}
struct cell {
char a; // active/empty state of cell
sfColor fColor; // fill color
+ unsigned int color;
};
@@ -39,13 +43,13 @@ struct shape {
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
+ sfRectangleShape *p[FLD_SIZE_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;
+ unsigned int id;
};
void init_field(struct field *fld);
diff --git a/include/tet_conf.h b/include/tet_conf.h
index 44da289..134e8a9 100644
--- a/include/tet_conf.h
+++ b/include/tet_conf.h
@@ -1,6 +1,7 @@
#define windowName_conf "Tetris CSFML" // Window name
#define UIBGCOLOR sfColor_fromRGB(26, 26, 26) // Field background
#define UIFGINACTIVECOLOR sfColor_fromRGB(55, 59, 65) // Field inactive cell outline
+#define OUT_THICK 1
#define UIFGACTIVECOLOR sfColor_fromRGB(40, 42, 46) // Field active cell outline
#define LCOLOR sfColor_fromRGB(222, 147, 95) // Orange color of L shape
#define RLCOLOR sfColor_fromRGB(95, 129, 157)
@@ -38,6 +39,9 @@
/*
+ * 22..........
+ * 21..........
+ * 20..........
* 19..........
* 18..........
* 17..........