summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Iezzi <aiezzi@alessandroiezzi.it>2025-05-21 16:34:55 +0200
committerAlessandro Iezzi <aiezzi@alessandroiezzi.it>2025-05-21 16:34:55 +0200
commit25c0bda9ca1e436370a9e2a671d3195de0e90902 (patch)
tree821dd0b7a767f0448b0037fc59a07f4a0aea3809
parentbf93cf0e5209815e51a2932288029d26f2153aca (diff)
downloadtris-25c0bda9ca1e436370a9e2a671d3195de0e90902.tar.gz
tris-25c0bda9ca1e436370a9e2a671d3195de0e90902.zip
Add a Cell list inside the TrisGame struct
-rw-r--r--src/main/game/game.c13
-rw-r--r--src/main/game/game.h8
2 files changed, 17 insertions, 4 deletions
diff --git a/src/main/game/game.c b/src/main/game/game.c
index 72d03b1..40547cc 100644
--- a/src/main/game/game.c
+++ b/src/main/game/game.c
@@ -40,6 +40,8 @@ int sign = 1;
int moves = 0;
+static void game_draw_field(TrisGame *game, float box_size, float x, float y);
+
static void
draw_sign(float x, float y)
{
@@ -102,16 +104,21 @@ game_mouse_button_pressed(float x, float y)
TrisGame *
game_init(int width, int height)
{
+ /* Init of the TrisGame */
TrisGame *game = malloc(sizeof(TrisGame));
if (game == NULL) {
log_error("Error allocating memory for the game");
exit(EXIT_FAILURE);
}
+ game->width = width;
+ game->height = height;
+ game->cells = list_create();
+
engine_init(width, height);
ui_set_title("Tris Game");
engine_set_mouse_button_listener(game_mouse_button_pressed);
- game_draw_field(0.5, 0, 0);
+ game_draw_field(game, 0.5, 0, 0);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
@@ -128,8 +135,8 @@ game_start()
engine_loop();
}
-void
-game_draw_field(float _box_size, float x, float y)
+static void
+game_draw_field(TrisGame *game, float _box_size, float x, float y)
{
float half_box = _box_size / 2;
engine_draw_line(x - half_box, y + half_box * 3, x - half_box, y - half_box * 3);
diff --git a/src/main/game/game.h b/src/main/game/game.h
index 298cafb..0cb80e0 100644
--- a/src/main/game/game.h
+++ b/src/main/game/game.h
@@ -20,12 +20,18 @@
#ifndef __GAME_H__
#define __GAME_H__
+#include "../util/list.h"
+
+typedef struct Cell {
+ float left, right, top, bottom;
+} Cell;
+
typedef struct TrisGame {
int width, height;
+ list_t *cells;
} TrisGame;
TrisGame *game_init(int width, int height);
void game_start(void);
-void game_draw_field(float box_size, float x, float y);
#endif /* __GAME_H__ */