diff --git a/tetris-game/scripts/board.gd b/tetris-game/scripts/board.gd index 9b4f87f..e0c8a20 100644 --- a/tetris-game/scripts/board.gd +++ b/tetris-game/scripts/board.gd @@ -201,16 +201,27 @@ func _lock_piece() -> void: func _clear_full_lines() -> int: var cleared_lines := 0 - for y in range(BOARD_HEIGHT - 1, -1, -1): + var y := BOARD_HEIGHT - 1 + + while y >= 0: var is_full := true for x in range(BOARD_WIDTH): if grid[y][x] == "": is_full = false break + if is_full: + # Remove this row and drop everything above it down by 1 _drop_lines_above(y) cleared_lines += 1 - y += 1 # re-check same row index (now replaced) + # IMPORTANT: + # Do NOT change y here. + # After dropping, a new row has moved into index y, + # so we re-check the same y in the next loop iteration. + else: + # Only move up when the current row was not cleared + y -= 1 + return cleared_lines func _drop_lines_above(row: int) -> void: