add match and watch helpers to player state
This commit is contained in:
parent
c284cb4796
commit
c6b12507d9
2 changed files with 30 additions and 5 deletions
|
|
@ -30,3 +30,25 @@ func _state_update(_delta: float) -> void:
|
||||||
|
|
||||||
func _state_physics_update(_delta: float) -> void:
|
func _state_physics_update(_delta: float) -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
func match_state(exclude: Array[StringName] = []) -> StringName:
|
||||||
|
var movement_vector: Vector2 = player.get_movement_vector()
|
||||||
|
|
||||||
|
if movement_vector.length() > player.DEADZONE:
|
||||||
|
if WALKING in exclude: return ""
|
||||||
|
return WALKING
|
||||||
|
elif movement_vector.length() < player.DEADZONE:
|
||||||
|
if IDLE in exclude: return ""
|
||||||
|
return IDLE
|
||||||
|
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
func watch_state(exclude: Array[StringName] = []) -> bool:
|
||||||
|
var next_state: StringName = match_state(exclude)
|
||||||
|
if next_state != "":
|
||||||
|
finished.emit(next_state)
|
||||||
|
return true
|
||||||
|
|
||||||
|
return false
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,14 @@ var next_state: StringName
|
||||||
|
|
||||||
func _enter(_previous_state_path: String, _data: Dictionary[StringName, Variant] = {}) -> void:
|
func _enter(_previous_state_path: String, _data: Dictionary[StringName, Variant] = {}) -> void:
|
||||||
print('entering idle')
|
print('entering idle')
|
||||||
#print('entered')
|
|
||||||
|
player.velocity = Vector2.ZERO
|
||||||
|
player.move_and_slide()
|
||||||
|
|
||||||
|
# TODO: animations
|
||||||
|
|
||||||
|
print('entered')
|
||||||
|
|
||||||
|
|
||||||
func _state_physics_update(_delta: float) -> void:
|
func _state_physics_update(_delta: float) -> void:
|
||||||
next_state = player.match_state([IDLE])
|
if watch_state([IDLE]): return
|
||||||
if next_state != "":
|
|
||||||
finished.emit(next_state)
|
|
||||||
return
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue