remove GameState

This commit is contained in:
Fabien Freling 2020-02-24 22:56:51 +01:00
parent 3e881d2868
commit 61efafe9a3
5 changed files with 32 additions and 73 deletions

View file

@ -2,6 +2,8 @@ tool
class_name Taquin
extends Control
signal state_changed(previous, new)
enum Direction { UP, DOWN, LEFT, RIGHT }
enum State {
MAIN,
@ -105,15 +107,13 @@ func _input(event):
# Disable input during animation
return
var game_state = get_node_or_null("/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
match current_state:
# If we are in the winning animation, fast-forward to game over screen
State.WINNING:
transition_to(State.GAME_OVER)
return
State.GAME_OVER:
return
#
# Handle keyboard input
@ -294,10 +294,7 @@ func check_solved() -> bool:
if pieces[c][r].order != 1 + c + r * columns:
return false
var game_state = get_node_or_null("/root/Main/GameState") as GameState
if game_state != null:
game_state.transition_to(GameState.State.WINNING)
transition_to(State.WINNING)
return true
func ensure_validity() -> void:
@ -316,25 +313,21 @@ func transition_to(state):
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:
match current_state:
State.WINNING:
$Particles2D.emitting = true
$Timer.start(-1)
GameState.State.GAME_OVER:
State.GAME_OVER:
$Particles2D.emitting = false
$Timer.stop()
emit_signal("state_changed", previous_state, current_state)
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)
transition_to(State.GAME_OVER)
func _on_AnimationPlayer_animation_finished(anim_name):
if anim_name == "MovingPiece":
commit_slide()
update()
check_solved()
match anim_name:
"MovingPiece":
commit_slide()
update()
check_solved()