add piece locking sound
This commit is contained in:
parent
ddd705f661
commit
3e881d2868
2 changed files with 43 additions and 10 deletions
|
@ -2,15 +2,26 @@ tool
|
|||
class_name Taquin
|
||||
extends Control
|
||||
|
||||
var Piece = preload("res://src/Piece.tscn")
|
||||
enum Direction { UP, DOWN, LEFT, RIGHT }
|
||||
enum State {
|
||||
MAIN,
|
||||
WINNING,
|
||||
GAME_OVER,
|
||||
}
|
||||
|
||||
const _state_transitions = {
|
||||
State.MAIN : [ State.WINNING ],
|
||||
State.WINNING : [ State.GAME_OVER ],
|
||||
State.GAME_OVER : [ State.MAIN ]
|
||||
}
|
||||
const Piece = preload("res://src/Piece.tscn")
|
||||
|
||||
export var rows: int = 4
|
||||
export var columns: int = 4
|
||||
export var width: int = 512
|
||||
export var height: int = 512
|
||||
export var difficulty: int = 10
|
||||
|
||||
enum Direction { UP, DOWN, LEFT, RIGHT }
|
||||
export(State) var current_state = State.MAIN
|
||||
|
||||
var interpiece := 4
|
||||
var min_padding := 15
|
||||
|
@ -240,11 +251,6 @@ func move_piece(direction) -> void:
|
|||
moving_piece_animation.track_set_key_value(moving_piece_track_index, 1, missing_piece.position)
|
||||
$AnimationPlayer.play("MovingPiece")
|
||||
|
||||
commit_slide()
|
||||
|
||||
update()
|
||||
check_solved()
|
||||
|
||||
func commit_slide():
|
||||
assert(current_sliding_piece != null)
|
||||
assert(current_origin != Vector2.ZERO)
|
||||
|
@ -256,6 +262,8 @@ func commit_slide():
|
|||
swap_pieces(missing_piece, current_sliding_piece)
|
||||
reset_position(missing_piece)
|
||||
|
||||
$AudioStreamPlayer.play()
|
||||
|
||||
ensure_validity()
|
||||
reset_slide()
|
||||
check_solved()
|
||||
|
@ -299,6 +307,18 @@ func ensure_validity() -> void:
|
|||
assert(piece.taquin_index.x == c)
|
||||
assert(piece.taquin_index.y == r)
|
||||
|
||||
func current_state_name() -> String:
|
||||
return State.keys()[current_state]
|
||||
|
||||
func transition_to(state):
|
||||
if current_state == state:
|
||||
return
|
||||
assert(state in _state_transitions[current_state])
|
||||
var previous_state = current_state
|
||||
current_state = state
|
||||
emit_signal("state_changed", previous_state, current_state)
|
||||
|
||||
|
||||
func _on_GameState_state_changed(previous, current):
|
||||
match current:
|
||||
GameState.State.WINNING:
|
||||
|
@ -312,3 +332,9 @@ 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)
|
||||
|
||||
func _on_AnimationPlayer_animation_finished(anim_name):
|
||||
if anim_name == "MovingPiece":
|
||||
commit_slide()
|
||||
update()
|
||||
check_solved()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue