From 679b4839a88a8d75abd37c7cac3e86290a4f738e Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Sun, 12 Jan 2020 19:35:20 +0100 Subject: [PATCH] add timer before showing game over --- game/src/Taquin.gd | 23 ++++++++++++++++++----- game/src/Taquin.tscn | 1 + 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/game/src/Taquin.gd b/game/src/Taquin.gd index 9b5277a..5d50426 100644 --- a/game/src/Taquin.gd +++ b/game/src/Taquin.gd @@ -78,6 +78,16 @@ func _input(event): # Disable input during animation return + var game_state = get_node("/root/Main/GameState") as GameState + if game_state != null: + match game_state.current_state: + # If we are in the winning animation, fast-forward to game over screen + GameState.State.WINNING: + game_state.transition_to(GameState.State.GAME_OVER) + return + GameState.State.GAME_OVER: + return + if event.is_action_pressed("ui_up"): move_piece(Direction.DOWN) if event.is_action_pressed("ui_down"): @@ -107,19 +117,14 @@ func move_piece(direction) -> bool: var destination: Vector2 = missing_piece match direction: Direction.UP: -# print("up") destination.y -= 1 Direction.DOWN: destination.y += 1 -# print("down") Direction.LEFT: destination.x -= 1 -# print("left") Direction.RIGHT: destination.x += 1 -# print("right") -# print(destination) if (destination.x < 0 || destination.x >= columns || destination.y < 0 || destination.y >= rows): print("impossible move") @@ -178,3 +183,11 @@ func _on_GameState_state_changed(previous, current): match current: GameState.State.WINNING: $Particles2D.emitting = true + $Timer.start(-1) + GameState.State.GAME_OVER: + $Timer.stop() + +func _on_Timer_timeout(): + var game_state = get_node("/root/Main/GameState") as GameState + if game_state != null: + game_state.transition_to(GameState.State.GAME_OVER) \ No newline at end of file diff --git a/game/src/Taquin.tscn b/game/src/Taquin.tscn index 05d2e0f..2c0f35a 100644 --- a/game/src/Taquin.tscn +++ b/game/src/Taquin.tscn @@ -81,3 +81,4 @@ process_material = SubResource( 2 ) [node name="Timer" type="Timer" parent="."] wait_time = 2.0 one_shot = true +[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]