summaryrefslogtreecommitdiff
path: root/src/main/game
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/game')
-rw-r--r--src/main/game/cell.c1
-rw-r--r--src/main/game/cell.h1
-rw-r--r--src/main/game/game.c25
3 files changed, 25 insertions, 2 deletions
diff --git a/src/main/game/cell.c b/src/main/game/cell.c
index e8322ff..cf5c11c 100644
--- a/src/main/game/cell.c
+++ b/src/main/game/cell.c
@@ -51,6 +51,7 @@ cell_new(float left, float right, float top, float bottom)
cell->cy = (cell->top + cell->bottom) / 2;
cell->sign = '\0';
+ cell->shape = NULL;
return cell;
}
diff --git a/src/main/game/cell.h b/src/main/game/cell.h
index e912ec0..8f52c91 100644
--- a/src/main/game/cell.h
+++ b/src/main/game/cell.h
@@ -27,6 +27,7 @@ typedef struct Cell {
float cx, cy;
bool filled;
char sign;
+ void *shape;
} Cell;
Cell *cell_new(float left, float right, float top, float bottom);
diff --git a/src/main/game/game.c b/src/main/game/game.c
index 31c9780..c72f81a 100644
--- a/src/main/game/game.c
+++ b/src/main/game/game.c
@@ -23,7 +23,6 @@
#include "../engine/engine.h"
#include "game.h"
#include "cell.h"
-#include "../engine/ui/ui.h"
#define WIN_PATTERNS 8
@@ -59,6 +58,20 @@ static void game_draw_field(TrisGame *game, float box_size);
static char game_next_sign(TrisGame *game);
static void
+draw_frames(void *data)
+{
+ if (data == NULL) return;
+ TrisGame *game = data;
+
+ for (int i = 0; i < BOARD_SIZE; i++) {
+ Cell *cell = game->cells[i];
+ if (cell->sign == SIGN_CIRCLE) {
+ engine_render_circle(cell->shape);
+ }
+ }
+}
+
+static void
game_restart(TrisGame *game)
{
game->ended = false;
@@ -67,7 +80,13 @@ game_restart(TrisGame *game)
Cell *cell = game->cells[i];
cell->filled = false;
cell->sign = '\0';
+
+ if (cell->shape != NULL) {
+ free(cell->shape);
+ }
}
+
+ engine_set_rendering_background_c(game->engine, game->board->default_color);
}
static void
@@ -107,7 +126,7 @@ draw_sign(TrisGame *game, Cell *cell)
cell_set_sign(cell, sign);
if (sign == SIGN_CIRCLE) {
- engine_draw_circle(x, y, l, 120, 1);
+ cell->shape = engine_circle_new(x, y, l, 120, 1);
game->sign = SIGN_CROSS;
} else if (sign == SIGN_CROSS) {
engine_draw_line(x - l, y + l, x + l, y - l);
@@ -166,6 +185,8 @@ game_init(int width, int height)
engine_set_window_title(game->engine, "Tris Game");
engine_set_mouse_button_listener(game_mouse_button_pressed, game);
+ engine_set_rendering_listener(game->engine, draw_frames, game);
+
game_draw_field(game, 0.5f);
return game;