move pieces even with null speed
This commit is contained in:
parent
f0c0c6d12e
commit
d5edc97e5c
|
@ -72,14 +72,8 @@ func _ready() -> void:
|
||||||
$Background.rect_size.y = height
|
$Background.rect_size.y = height
|
||||||
|
|
||||||
rng.randomize()
|
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)
|
new_game("normal")
|
||||||
shuffle(difficulty, 0.0)
|
|
||||||
|
|
||||||
func _input(event):
|
func _input(event):
|
||||||
if $AnimationPlayer.is_playing():
|
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)
|
moving_piece_animation.track_set_key_value(moving_piece_track_index, 1, missing_piece.position)
|
||||||
$AnimationPlayer.play("MovingPiece")
|
$AnimationPlayer.play("MovingPiece")
|
||||||
else:
|
else:
|
||||||
|
var previous_position = current_sliding_piece.position
|
||||||
|
current_sliding_piece.position = missing_piece.position
|
||||||
|
missing_piece.position = previous_position
|
||||||
commit_slide(false, false)
|
commit_slide(false, false)
|
||||||
update()
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
@ -252,6 +248,7 @@ func commit_slide(audio: bool, check_solved: bool):
|
||||||
|
|
||||||
ensure_validity()
|
ensure_validity()
|
||||||
reset_slide()
|
reset_slide()
|
||||||
|
update()
|
||||||
if check_solved:
|
if check_solved:
|
||||||
check_solved()
|
check_solved()
|
||||||
|
|
||||||
|
@ -364,7 +361,7 @@ func init(pieces_order: Array, hidden_piece: int) -> void:
|
||||||
for c in range(pieces.size()):
|
for c in range(pieces.size()):
|
||||||
for r in range(pieces[c].size()):
|
for r in range(pieces[c].size()):
|
||||||
var piece: Piece = pieces[c][r].queue_free()
|
var piece: Piece = pieces[c][r].queue_free()
|
||||||
pieces.clear()
|
pieces.clear()
|
||||||
|
|
||||||
for c in range(columns):
|
for c in range(columns):
|
||||||
var pieces_row: Array = []
|
var pieces_row: Array = []
|
||||||
|
@ -401,22 +398,9 @@ func init(pieces_order: Array, hidden_piece: int) -> void:
|
||||||
|
|
||||||
pieces.append(pieces_row)
|
pieces.append(pieces_row)
|
||||||
|
|
||||||
#
|
func new_game(difficulty_mode: String) -> void:
|
||||||
# Signals
|
print_debug("difficulty mode: ", difficulty_mode)
|
||||||
#
|
match difficulty_mode:
|
||||||
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:
|
|
||||||
"easy":
|
"easy":
|
||||||
rows = 3
|
rows = 3
|
||||||
columns = 3
|
columns = 3
|
||||||
|
@ -441,3 +425,18 @@ func _on_NewGamePanel_start_triggered(preferences):
|
||||||
var hidden_piece = rows * columns # Last piece is hidden
|
var hidden_piece = rows * columns # Last piece is hidden
|
||||||
init(pieces_order, hidden_piece)
|
init(pieces_order, hidden_piece)
|
||||||
shuffle(difficulty, 0.0)
|
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…
Reference in a new issue