tetris
game over detection
bendn 2022-08-14
parent 7f7347d · commit c23beb0
-rw-r--r--Tetris.gd8
1 files changed, 7 insertions, 1 deletions
diff --git a/Tetris.gd b/Tetris.gd
index 34de601..81e78a3 100644
--- a/Tetris.gd
+++ b/Tetris.gd
@@ -72,7 +72,11 @@ func draw_board(mat: Array = matrix.duplicate(true), shape: TetrisPiece = curren
shape.embed(mat)
for y in range(ROWS):
for x in range(COLUMNS):
- get_square(Vector2(x, y)).color = colors[mat[y][x] - 1] if mat[y][x] > 0 else Color.transparent
+ get_square(Vector2(x, y)).color = (
+ colors[mat[y][x] - 1]
+ if mat[y][x] > 0
+ else Color.transparent
+ )
func _input(event):
@@ -96,6 +100,8 @@ func tick(create_timer := true):
t.connect("timeout", self, "tick")
if not current_shape.move(Vector2(0, 1), matrix): # invalid move: cant go down
+ if current_shape.position.y == 0:
+ get_tree().reload_current_scene()
current_shape.embed(matrix)
current_shape = TetrisPiece.new(Vector2(randi() % (COLUMNS - 4), 0))
Logic.clear_lines(matrix)