diff --git a/main.c b/main.c index a4d8300..a5f688f 100644 --- a/main.c +++ b/main.c @@ -34,6 +34,8 @@ static int board[BOARD_HEIGHT][BOARD_WIDTH] = {0}; bool is_dragging = false; Vector2 drag_start_pos = {0, 0}; +int score = 0; +int moves_made = 0; // Depending on the direction, move the tiles and check if we can merge with the // tiles in that direction. We merge the tiles only if they are of the same value @@ -75,6 +77,7 @@ void move(MOVE_DIRECTION direction) { merged[target_y][x] = true; board[target_y][x] *= 2; board[y][x] = 0; + score += board[target_y][x]; } } } @@ -108,6 +111,7 @@ void move(MOVE_DIRECTION direction) { merged[target_y][x] = true; board[target_y][x] *= 2; board[y][x] = 0; + score += board[target_y][x]; } } } @@ -141,6 +145,7 @@ void move(MOVE_DIRECTION direction) { merged[y][target_x] = true; board[y][target_x] *= 2; board[y][x] = 0; + score += board[y][target_x]; } } } @@ -174,12 +179,14 @@ void move(MOVE_DIRECTION direction) { merged[y][target_x] = true; board[y][target_x] *= 2; board[y][x] = 0; + score += board[y][target_x]; } } } break; } } + moves_made++; } bool spawn_tile() { @@ -209,8 +216,23 @@ bool spawn_tile() { void handle_mouse_input() { if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { - is_dragging = true; drag_start_pos = GetMousePosition(); + if (drag_start_pos.x >= 500 && drag_start_pos.x <= 775 && drag_start_pos.y >= 455 && drag_start_pos.y <= 479) { + // Reset button + for (int y = 0; y < BOARD_HEIGHT; y++) { + for (int x = 0; x < BOARD_WIDTH; x++) { + board[y][x] = 0; + } + } + score = 0; + moves_made = 0; + spawn_tile(); + spawn_tile(); + spawn_tile(); + return; + } + + is_dragging = true; } else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON) && is_dragging) { Vector2 current_pos = GetMousePosition(); @@ -276,6 +298,14 @@ int main() { } } } + + DrawText(TextFormat("Score: %d", score), 600, BOARD_MARGIN, 20, BLACK); + DrawText(TextFormat("Moves used: %d", moves_made), 600, BOARD_MARGIN + 20, 20, BLACK); + + // Reset button + DrawRectangle(500, 455, 275, 24, RED); + DrawText("Reset", 500 + 275 / 2 - MeasureText("Reset", 20) / 2, 455 + 4, 20, WHITE); + EndDrawing(); handle_mouse_input(); }