summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Iezzi <aiezzi@alessandroiezzi.it>2025-05-22 00:01:51 +0200
committerAlessandro Iezzi <aiezzi@alessandroiezzi.it>2025-05-22 00:01:51 +0200
commitc07d2adb16532691e22a34d11ad87b56a4dc1a89 (patch)
tree3009daf2f2e2a336912305a3735c166969914450
parent8d3d0a98d71181d5f65b4f08d40976a9824ba68a (diff)
downloadtris-c07d2adb16532691e22a34d11ad87b56a4dc1a89.tar.gz
tris-c07d2adb16532691e22a34d11ad87b56a4dc1a89.zip
Change the logic on drawing signs
-rw-r--r--src/main/game/cell.c3
-rw-r--r--src/main/game/cell.h1
-rw-r--r--src/main/game/game.c10
3 files changed, 5 insertions, 9 deletions
diff --git a/src/main/game/cell.c b/src/main/game/cell.c
index c8151b2..9227da5 100644
--- a/src/main/game/cell.c
+++ b/src/main/game/cell.c
@@ -47,6 +47,9 @@ cell_new(float left, float right, float top, float bottom)
cell->bottom = bottom;
cell->filled = false;
+ cell->cx = (cell->right + cell->left) / 2;
+ cell->cy = (cell->top + cell->bottom) / 2;
+
return cell;
}
diff --git a/src/main/game/cell.h b/src/main/game/cell.h
index 000edfb..9a0a213 100644
--- a/src/main/game/cell.h
+++ b/src/main/game/cell.h
@@ -24,6 +24,7 @@
typedef struct Cell {
float left, right, top, bottom;
+ float cx, cy;
bool filled;
} Cell;
diff --git a/src/main/game/game.c b/src/main/game/game.c
index 2e2db8f..e92e283 100644
--- a/src/main/game/game.c
+++ b/src/main/game/game.c
@@ -78,6 +78,7 @@ loop_cells(list_t *cells, float x, float y)
do {
Cell *cell = current->data;
if (!cell_is_filled(cell) && cell_within_bounds(cell, x, y)) {
+ draw_sign(cell->cx, cell->cy);
cell_set_filled(cell, true);
}
current = current->next;
@@ -94,35 +95,26 @@ game_mouse_button_pressed(float x, float y, void *data)
if (x >= xmin && x <= xmax && y >= ymin && y <= ymax) {
if (y >= first_row) {
if (x <= first_col && field_matrix[0][0] == -1) {
- draw_sign(half_first_col, half_first_row);
field_matrix[0][0] = sign;
} else if (x >= first_col && x <= second_col && field_matrix[0][1] == -1) {
- draw_sign(half_second_col, half_first_row);
field_matrix[0][1] = sign;
} else if (x >= second_col && field_matrix[0][2] == -1) {
- draw_sign(half_third_col, half_first_row);
field_matrix[0][2] = sign;
}
} else if (y >= second_row) {
if (x <= first_col && field_matrix[1][0] == -1) {
- draw_sign(half_first_col, half_second_row);
field_matrix[1][0] = sign;
} else if (x >= first_col && x <= second_col && field_matrix[1][1] == -1) {
- draw_sign(half_second_col, half_second_row);
field_matrix[1][1] = sign;
} else if (x >= second_col && field_matrix[1][2] == -1) {
- draw_sign(half_third_col, half_second_row);
field_matrix[1][2] = sign;
}
} else if (y >= third_row) {
if (x <= first_col && field_matrix[2][0] == -1) {
- draw_sign(half_first_col, half_third_row);
field_matrix[2][0] = sign;
} else if (x >= first_col && x <= second_col && field_matrix[2][1] == -1) {
- draw_sign(half_second_col, half_third_row);
field_matrix[2][1] = sign;
} else if (x >= second_col && field_matrix[2][2] == -1) {
- draw_sign(half_third_col, half_third_row);
field_matrix[2][2] = sign;
}
}