From 45e9fb0bcdf8a2a46d3361339d1f57244d05e75c Mon Sep 17 00:00:00 2001 From: Abdellah El Morabit Date: Sat, 11 Jan 2025 08:39:42 +0100 Subject: working on the collision detection bug --- .cache/clangd/index/TETRIS.c.EC74E3FB69CEE55B.idx | Bin 4270 -> 4526 bytes TETRIS.c | 26 ++++++++++++++++++++-- tetris | Bin 51576 -> 51672 bytes 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/.cache/clangd/index/TETRIS.c.EC74E3FB69CEE55B.idx b/.cache/clangd/index/TETRIS.c.EC74E3FB69CEE55B.idx index 679cba0..5742a7a 100644 Binary files a/.cache/clangd/index/TETRIS.c.EC74E3FB69CEE55B.idx and b/.cache/clangd/index/TETRIS.c.EC74E3FB69CEE55B.idx differ diff --git a/TETRIS.c b/TETRIS.c index b2359da..eb0366c 100644 --- a/TETRIS.c +++ b/TETRIS.c @@ -205,7 +205,7 @@ void SAVE_TETROMINO(TETROMINO *tetromino, int **GRID) { int GRIDX = tetromino->x + x; int GRIDY = tetromino->y + y; - if (GRIDX <= COLUMNS && GRIDY >= 0 && GRIDY <= ROWS - 2) + if (GRIDX < COLUMNS && GRIDY >= 0 && GRIDY < ROWS) GRID[GRIDY][GRIDX] = 1; } } @@ -219,7 +219,7 @@ void DRAW_SAVED_TETROMINO(int **GRID, TETROMINO *tetromino) for (int x = 0; x < COLUMNS; x++) { if (GRID[y][x] == 1) - DrawRectangle(x * CELL_WIDTH, y * CELL_HEIGHT, CELL_WIDTH, CELL_HEIGHT, tetromino->color); + DrawRectangle((x * CELL_WIDTH) , (y * CELL_HEIGHT) , CELL_WIDTH, CELL_HEIGHT, tetromino->color); } } } @@ -237,6 +237,27 @@ void DRAW_STATS(TETROMINO *tetromino) DrawText(CURRENT_X_POSITION, 10, 50, FONT_SIZE, BLUE); } +void CHECK_FULL_LINE(int **GRID) +{ + int LAST_LINE_Y = ROWS - 2; + bool FULL_LINE = true; + + for (int x = 0; x <= COLUMNS; x++) + { + if (GRID[LAST_LINE_Y][x] == 0) + { + FULL_LINE = false; + } + + } + if (!FULL_LINE){ + for (int x = 0; x <= COLUMNS; x++) + { + GRID[LAST_LINE_Y][x] = GRID[LAST_LINE_Y][0]; + } + } +} + int main() { InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Tetris"); @@ -246,6 +267,7 @@ int main() int **GRID = CREATE_TETROMINOS_GRID(ROWS, COLUMNS); if (!GRID) { + printf("FAILED TO ALLOCATE MEMORY FOR THE GRID"); CloseWindow(); return 1; } diff --git a/tetris b/tetris index a12c677..d93bac4 100755 Binary files a/tetris and b/tetris differ -- cgit v1.2.3-70-g09d2