diff options
Diffstat (limited to 'src/main/game/game.c')
-rw-r--r-- | src/main/game/game.c | 25 |
1 files changed, 23 insertions, 2 deletions
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; |