move pieces even with null speed
This commit is contained in:
		
							parent
							
								
									f0c0c6d12e
								
							
						
					
					
						commit
						d5edc97e5c
					
				
					 1 changed files with 24 additions and 25 deletions
				
			
		| 
						 | 
				
			
			@ -73,13 +73,7 @@ func _ready() -> void:
 | 
			
		|||
	
 | 
			
		||||
	rng.randomize()
 | 
			
		||||
	
 | 
			
		||||
	var pieces_order: Array = []
 | 
			
		||||
	for order in range(1, rows * columns + 1):
 | 
			
		||||
		pieces_order.append(order)
 | 
			
		||||
	var hidden_piece = rows * columns # Last piece is hidden
 | 
			
		||||
	
 | 
			
		||||
	init(pieces_order, hidden_piece)
 | 
			
		||||
	shuffle(difficulty, 0.0)
 | 
			
		||||
	new_game("normal")
 | 
			
		||||
 | 
			
		||||
func _input(event):
 | 
			
		||||
	if $AnimationPlayer.is_playing():
 | 
			
		||||
| 
						 | 
				
			
			@ -231,8 +225,10 @@ func move_piece(direction, speed: float) -> bool:
 | 
			
		|||
		moving_piece_animation.track_set_key_value(moving_piece_track_index, 1, missing_piece.position)
 | 
			
		||||
		$AnimationPlayer.play("MovingPiece")
 | 
			
		||||
	else:
 | 
			
		||||
		var previous_position = current_sliding_piece.position
 | 
			
		||||
		current_sliding_piece.position = missing_piece.position
 | 
			
		||||
		missing_piece.position = previous_position
 | 
			
		||||
		commit_slide(false, false)
 | 
			
		||||
		update()
 | 
			
		||||
 | 
			
		||||
	return true
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -252,6 +248,7 @@ func commit_slide(audio: bool, check_solved: bool):
 | 
			
		|||
 | 
			
		||||
	ensure_validity()
 | 
			
		||||
	reset_slide()
 | 
			
		||||
	update()
 | 
			
		||||
	if check_solved:
 | 
			
		||||
		check_solved()
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -401,22 +398,9 @@ func init(pieces_order: Array, hidden_piece: int) -> void:
 | 
			
		|||
 | 
			
		||||
		pieces.append(pieces_row)
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Signals
 | 
			
		||||
#
 | 
			
		||||
func _on_Timer_timeout():
 | 
			
		||||
	transition_to(State.GAME_OVER)
 | 
			
		||||
 | 
			
		||||
func _on_AnimationPlayer_animation_finished(anim_name):
 | 
			
		||||
	match anim_name:
 | 
			
		||||
		"MovingPiece":
 | 
			
		||||
			commit_slide(true, true)
 | 
			
		||||
			update()
 | 
			
		||||
			check_solved()
 | 
			
		||||
 | 
			
		||||
func _on_NewGamePanel_start_triggered(preferences):
 | 
			
		||||
	var difficulty = preferences.get_value("game", "difficulty", "normal")
 | 
			
		||||
	match difficulty:
 | 
			
		||||
func new_game(difficulty_mode: String) -> void:
 | 
			
		||||
	print_debug("difficulty mode: ", difficulty_mode)
 | 
			
		||||
	match difficulty_mode:
 | 
			
		||||
		"easy":
 | 
			
		||||
			rows = 3
 | 
			
		||||
			columns = 3
 | 
			
		||||
| 
						 | 
				
			
			@ -441,3 +425,18 @@ func _on_NewGamePanel_start_triggered(preferences):
 | 
			
		|||
	var hidden_piece = rows * columns # Last piece is hidden
 | 
			
		||||
	init(pieces_order, hidden_piece)
 | 
			
		||||
	shuffle(difficulty, 0.0)
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Signals
 | 
			
		||||
#
 | 
			
		||||
func _on_Timer_timeout():
 | 
			
		||||
	transition_to(State.GAME_OVER)
 | 
			
		||||
 | 
			
		||||
func _on_AnimationPlayer_animation_finished(anim_name):
 | 
			
		||||
	match anim_name:
 | 
			
		||||
		"MovingPiece":
 | 
			
		||||
			commit_slide(true, true)
 | 
			
		||||
 | 
			
		||||
func _on_NewGamePanel_start_triggered(preferences):
 | 
			
		||||
	var difficulty_mode = preferences.get_value("game", "difficulty", "normal")
 | 
			
		||||
	new_game(difficulty_mode)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue