add timer before showing game over
This commit is contained in:
		
							parent
							
								
									d2c1aa044f
								
							
						
					
					
						commit
						679b4839a8
					
				
					 2 changed files with 19 additions and 5 deletions
				
			
		| 
						 | 
					@ -78,6 +78,16 @@ func _input(event):
 | 
				
			||||||
		# Disable input during animation
 | 
							# Disable input during animation
 | 
				
			||||||
		return
 | 
							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"):
 | 
						if event.is_action_pressed("ui_up"):
 | 
				
			||||||
		move_piece(Direction.DOWN)
 | 
							move_piece(Direction.DOWN)
 | 
				
			||||||
	if event.is_action_pressed("ui_down"):
 | 
						if event.is_action_pressed("ui_down"):
 | 
				
			||||||
| 
						 | 
					@ -107,19 +117,14 @@ func move_piece(direction) -> bool:
 | 
				
			||||||
	var destination: Vector2 = missing_piece
 | 
						var destination: Vector2 = missing_piece
 | 
				
			||||||
	match direction:
 | 
						match direction:
 | 
				
			||||||
		Direction.UP:
 | 
							Direction.UP:
 | 
				
			||||||
#			print("up")
 | 
					 | 
				
			||||||
			destination.y -= 1
 | 
								destination.y -= 1
 | 
				
			||||||
		Direction.DOWN:
 | 
							Direction.DOWN:
 | 
				
			||||||
			destination.y += 1
 | 
								destination.y += 1
 | 
				
			||||||
#			print("down")
 | 
					 | 
				
			||||||
		Direction.LEFT:
 | 
							Direction.LEFT:
 | 
				
			||||||
			destination.x -= 1
 | 
								destination.x -= 1
 | 
				
			||||||
#			print("left")
 | 
					 | 
				
			||||||
		Direction.RIGHT:
 | 
							Direction.RIGHT:
 | 
				
			||||||
			destination.x += 1
 | 
								destination.x += 1
 | 
				
			||||||
#			print("right")
 | 
					 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
#	print(destination)
 | 
					 | 
				
			||||||
	if (destination.x < 0 || destination.x >= columns
 | 
						if (destination.x < 0 || destination.x >= columns
 | 
				
			||||||
	|| destination.y < 0 || destination.y >= rows):
 | 
						|| destination.y < 0 || destination.y >= rows):
 | 
				
			||||||
		print("impossible move")
 | 
							print("impossible move")
 | 
				
			||||||
| 
						 | 
					@ -178,3 +183,11 @@ func _on_GameState_state_changed(previous, current):
 | 
				
			||||||
	match current:
 | 
						match current:
 | 
				
			||||||
		GameState.State.WINNING:
 | 
							GameState.State.WINNING:
 | 
				
			||||||
			$Particles2D.emitting = true
 | 
								$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)
 | 
				
			||||||
| 
						 | 
					@ -81,3 +81,4 @@ process_material = SubResource( 2 )
 | 
				
			||||||
[node name="Timer" type="Timer" parent="."]
 | 
					[node name="Timer" type="Timer" parent="."]
 | 
				
			||||||
wait_time = 2.0
 | 
					wait_time = 2.0
 | 
				
			||||||
one_shot = true
 | 
					one_shot = true
 | 
				
			||||||
 | 
					[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue