From 3bd53ebeea1788fbe35ce7d49a1b3e2535bbfd57 Mon Sep 17 00:00:00 2001 From: Jan Lerking Date: Sat, 6 Dec 2025 16:42:45 +0100 Subject: [PATCH] #3. /JL --- tetris-game/scripts/board.gd | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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: