summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Iezzi <aiezzi@alessandroiezzi.it>2025-05-22 11:50:36 +0200
committerAlessandro Iezzi <aiezzi@alessandroiezzi.it>2025-05-22 11:50:36 +0200
commit47ab4de4487037b06b41744713f6a5012e119f46 (patch)
treeb78b6f090f5ab68b58da8e3872415d0db2f308c8
parent0a847cc16afb59b0b9f9f36bfffa43b912536e8a (diff)
downloadtris-47ab4de4487037b06b41744713f6a5012e119f46.tar.gz
tris-47ab4de4487037b06b41744713f6a5012e119f46.zip
Change color of the background on winning
-rw-r--r--src/main/engine/engine.c15
-rw-r--r--src/main/engine/engine.h2
-rw-r--r--src/main/game/game.c4
-rw-r--r--src/main/game/game.h2
4 files changed, 20 insertions, 3 deletions
diff --git a/src/main/engine/engine.c b/src/main/engine/engine.c
index 5ea4c4f..97ba445 100644
--- a/src/main/engine/engine.c
+++ b/src/main/engine/engine.c
@@ -79,6 +79,7 @@ engine_new(int w, int h)
exit(EXIT_FAILURE);
}
engine->circles = list_create();
+ engine_set_rendering_background(engine, 0.0f, 0.0f, 0.2f, 1.0f);
width = w;
height = h;
@@ -200,7 +201,9 @@ draw_circles()
static void
draw_frames()
{
- glClearColor(0.0f, 0.0f, 0.2f, 1.0f);
+ Color *bk = engine->rendering_background;
+
+ glClearColor(bk->r, bk->g, bk->b, bk->a);
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
@@ -309,3 +312,13 @@ engine_input(void (*f_input)(int engine_input))
ui_set_generic_listener(engine_dispatch_ui_events);
dispatch_ui_event = f_input;
}
+
+void
+engine_set_rendering_background(Engine *engine, float r, float g, float b, float a)
+{
+ if (engine->rendering_background == NULL) {
+ engine->rendering_background = color_new(r, g, b, a);
+ } else {
+ color_set_rgba(engine->rendering_background, r, g, b, a);
+ }
+}
diff --git a/src/main/engine/engine.h b/src/main/engine/engine.h
index d6fe1d1..f77fc4e 100644
--- a/src/main/engine/engine.h
+++ b/src/main/engine/engine.h
@@ -33,9 +33,11 @@ typedef struct {
list_t *circles;
void (*draw_frame)();
float ortho_left, ortho_right, ortho_top, ortho_bottom;
+ Color *rendering_background;
} Engine;;
Engine *engine_new(int width, int height);
+void engine_set_rendering_background(Engine *engine, float r, float g, float b, float a);
void engine_draw_circle(float cx, float cy, float r, int num_segments, int outline);
void engine_draw_line(float x1, float y1, float x2, float y2);
void engine_loop(void);
diff --git a/src/main/game/game.c b/src/main/game/game.c
index f1e5bdd..ee35f7d 100644
--- a/src/main/game/game.c
+++ b/src/main/game/game.c
@@ -73,7 +73,7 @@ check_win(TrisGame *game)
if (game->cells[i0]->sign != '\0'
&& game->cells[i0]->sign == game->cells[i1]->sign
&& game->cells[i1]->sign == game->cells[i2]->sign) {
- printf("Win!\n");
+ engine_set_rendering_background(game->engine, 0.0f, 0.5f, 0.0f, 1.0f);
}
}
}
@@ -135,8 +135,8 @@ game_init(int width, int height)
game->height = height;
game->sign = SIGN_CIRCLE;
game->moves = 0;
+ game->engine = engine_new(width, height);
- engine_new(width, height);
ui_set_title("Tris Game");
engine_set_mouse_button_listener(game_mouse_button_pressed, game);
diff --git a/src/main/game/game.h b/src/main/game/game.h
index 3d10bea..d119f67 100644
--- a/src/main/game/game.h
+++ b/src/main/game/game.h
@@ -23,12 +23,14 @@
#define BOARD_SIZE 9
#include "cell.h"
+#include "../engine/engine.h"
typedef struct TrisGame {
int width, height;
Cell *cells[BOARD_SIZE];
char sign; /* x = cross and o = circle */
int moves;
+ Engine *engine;
} TrisGame;
TrisGame *game_init(int width, int height);