diff options
| author | Abdellah El Morabit <nsrddyn@gmail.com> | 2025-01-18 19:23:46 +0100 |
|---|---|---|
| committer | Abdellah El Morabit <nsrddyn@gmail.com> | 2025-01-18 19:23:46 +0100 |
| commit | b6922cf9939c3a88ca8df9e36a32fd7552edc133 (patch) | |
| tree | 9854ab2ce1cf1de28b05637968bc6ca46c7e6c3f /TETRIS.c | |
| parent | 9ff91999b122df64c910b3d7ebed1ceda949e0c0 (diff) | |
added some debugging inforamtion to find the error in the future
Diffstat (limited to 'TETRIS.c')
| -rw-r--r-- | TETRIS.c | 44 |
1 files changed, 25 insertions, 19 deletions
@@ -204,47 +204,50 @@ void CHECK_FULL_LINE(int **GRID) // Detect if the active tetromino is hitting another tetromino +// Detect if the active tetromino is hitting another tetromino int COLLISION_DETECTION(TETROMINO *tetromino, int **GRID) { + int TETROMINO_WIDTH = 0; + int TETROMINO_HEIGHT = 0; - // FIND THE WIDTH AND HEIGHT OF THE ACTIVE TETROMINO - - int CURRENT_LOWEST_INDEX_X = 0; - int CURRENT_LOWEST_INDEX_Y = 0; - + // Determine the bounding width and height of the tetromino for (int y = 0; y < TETROMINO_SIZE_HEIGHT; y++) { for (int x = 0; x < TETROMINO_SIZE_WIDTH; x++) { - if (tetromino->blocks[y][x] == 1) - { - CURRENT_LOWEST_INDEX_X = x; - CURRENT_LOWEST_INDEX_Y = y; - } + if (tetromino->blocks[y][x] == 1) + { + // Update width and height based on the furthest active blocks + if (x + 1 > TETROMINO_WIDTH) + TETROMINO_WIDTH = x + 1; + if (y + 1 > TETROMINO_HEIGHT) + TETROMINO_HEIGHT = y + 1; + } } } - - for (int i = 0; i < TETROMINO_SIZE_HEIGHT; i++) + // Check for collision with the grid + for (int i = 0; i < TETROMINO_HEIGHT; i++) { - for (int j = 0; j < TETROMINO_SIZE_WIDTH; j++) + for (int j = 0; j < TETROMINO_WIDTH; j++) { if (tetromino->blocks[i][j] == 1) { int GRID_X = tetromino->x + j; int GRID_Y = tetromino->y + i; - - // BLOCKS COLLISION - if (GRID_Y > 0 && GRID[GRID_Y][GRID_X] != 0) - return 1; + // Check if we are within the grid boundaries and if there is a block + if (GRID_Y >= 0 && GRID_X >= 0 && GRID[GRID_Y][GRID_X] != 0) + { + return 1; // Collision detected + } } } } - // NO COLLISION + + // No collision return 0; } - int *ROTATE_ACTIVE_TETROMINO(TETROMINO *tetromino, int **GRID) { int *ROTATED_TETROMINO; @@ -394,6 +397,9 @@ int main() SCORE++; SAVE_TETROMINO(&ACTIVE_TETROMINO, GRID); ACTIVE_TETROMINO = SPAWN_TETROMINO(); + printf("DEBUGGING INFORMATION - XOR %p: ",&ACTIVE_TETROMINO.x); + printf("DEBUGGING INFORMATION - YOR %p: ",&ACTIVE_TETROMINO.y); + } EndDrawing(); |
