summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbdellah El Morabit <nsrddyn@gmail.com>2025-01-11 08:39:42 +0100
committerAbdellah El Morabit <nsrddyn@gmail.com>2025-01-11 08:39:42 +0100
commit45e9fb0bcdf8a2a46d3361339d1f57244d05e75c (patch)
tree3d56d312e43f57fb7fa9ab72ad8c4e7c000d8c74
parent0ae17eb77565e1a977d10beec73788abab7be2d5 (diff)
working on the collision detection bug
-rw-r--r--.cache/clangd/index/TETRIS.c.EC74E3FB69CEE55B.idxbin4270 -> 4526 bytes
-rw-r--r--TETRIS.c26
-rwxr-xr-xtetrisbin51576 -> 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
--- a/.cache/clangd/index/TETRIS.c.EC74E3FB69CEE55B.idx
+++ b/.cache/clangd/index/TETRIS.c.EC74E3FB69CEE55B.idx
Binary files 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
--- a/tetris
+++ b/tetris
Binary files differ