From c07d2adb16532691e22a34d11ad87b56a4dc1a89 Mon Sep 17 00:00:00 2001 From: Alessandro Iezzi Date: Thu, 22 May 2025 00:01:51 +0200 Subject: Change the logic on drawing signs --- src/main/game/cell.c | 3 +++ src/main/game/cell.h | 1 + src/main/game/game.c | 10 +--------- 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; } } -- cgit v1.2.3