@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user