diff options
Diffstat (limited to 'TETRIS.c')
| -rw-r--r-- | TETRIS.c | 22 |
1 files changed, 11 insertions, 11 deletions
@@ -128,8 +128,8 @@ int COLLISION_DETECTION(TETROMINO *ACTIVE_TETROMINO, int **GRID) for (int y = 0; y < TETROMINO_SIZE; y++) { for (int x = 0; x < TETROMINO_SIZE; x++) { if (ACTIVE_TETROMINO->blocks[y][x] == 1) { - int GRID_Y = ACTIVE_TETROMINO->x + x; - int GRID_X = ACTIVE_TETROMINO->y + y; + int GRID_X = ACTIVE_TETROMINO->x + x; + int GRID_Y = ACTIVE_TETROMINO->y + y; if (GRID_X < 0 || GRID_X >= COLUMNS || GRID_Y >= ROWS) { // COLLISION @@ -182,15 +182,15 @@ TETROMINO SPAWN_TETROMINO() return tetromino; } -void MOVE_TETROMINO(TETROMINO *tetromino) +void MOVE_TETROMINO(TETROMINO *tetromino, int **GRID) { - if (!IsKeyDown(KEY_LEFT_SHIFT)) + if (!IsKeyDown(KEY_LEFT_SHIFT) && COLLISION_DETECTION(tetromino, GRID) == 0) { - if (IsKeyDown(KEY_RIGHT) && tetromino->x + TETROMINO_SIZE < COLUMNS + 1) + if (IsKeyDown(KEY_RIGHT) && tetromino->x + TETROMINO_SIZE < COLUMNS) tetromino->x++; if (IsKeyDown(KEY_LEFT) && tetromino->x > 0) tetromino->x--; - if (IsKeyDown(KEY_DOWN) && tetromino->y < ROWS + 1 ) + if (IsKeyDown(KEY_DOWN) && tetromino->y < ROWS - 2 ) tetromino->y++; } } @@ -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) + if (GRIDX <= COLUMNS && GRIDY >= 0 && GRIDY <= ROWS - 2) GRID[GRIDY][GRIDX] = 1; } } @@ -233,8 +233,8 @@ void DRAW_STATS(TETROMINO *tetromino) char CURRENT_Y_POSITION[16], CURRENT_X_POSITION[16]; sprintf(CURRENT_Y_POSITION, "Y: %d", tetromino->y); sprintf(CURRENT_X_POSITION, "X: %d", tetromino->x); - DrawText(CURRENT_Y_POSITION, 10, 20, FONT_SIZE, BLUE); - DrawText(CURRENT_X_POSITION, 10, 30, FONT_SIZE, BLUE); + DrawText(CURRENT_Y_POSITION, 10, 30, FONT_SIZE, BLUE); + DrawText(CURRENT_X_POSITION, 10, 50, FONT_SIZE, BLUE); } int main() @@ -258,9 +258,9 @@ int main() DRAW_GRID_BACKGROUND(); DRAW_SAVED_TETROMINO(GRID, &ACTIVE_TETROMINO); DRAW_TETROMINO(&ACTIVE_TETROMINO); - DRAW_STATS(); + DRAW_STATS(&ACTIVE_TETROMINO); - MOVE_TETROMINO(&ACTIVE_TETROMINO); + MOVE_TETROMINO(&ACTIVE_TETROMINO, GRID); if (ACTIVE_TETROMINO.y == ROWS - 2 && COLLISION_DETECTION(&ACTIVE_TETROMINO,GRID) == 0) { |
