Added a StateMachine interface
This commit is contained in:
parent
bbe611c1aa
commit
58fa20d2e7
@ -1,18 +1,39 @@
|
||||
extends Node
|
||||
class_name StateMachine
|
||||
extends Node
|
||||
class_name StateMachine
|
||||
|
||||
var state = null
|
||||
var previous_state = null
|
||||
var state = null setget set_state
|
||||
var previous_state = null
|
||||
var states = {}
|
||||
|
||||
onready var parent = get_parent()
|
||||
onready var parent = get_parent()
|
||||
|
||||
func _state_logic(delta):
|
||||
func _physics_process(delta):
|
||||
if state != null:
|
||||
_state_logic(delta)
|
||||
var transition = _get_transition(delta)
|
||||
if transition != null:
|
||||
set_state(transition)
|
||||
|
||||
func _state_logic(_delta):
|
||||
pass
|
||||
|
||||
func _get_transition(delta):
|
||||
func _get_transition(_delta):
|
||||
return null
|
||||
|
||||
func _enter_state(new_state, old_state):
|
||||
func _enter_state(_new_state, _previous_state):
|
||||
pass
|
||||
|
||||
func _exit_state
|
||||
func _exit_state(_previous_state, _new_state):
|
||||
pass
|
||||
|
||||
func set_state(new_state):
|
||||
previous_state = state
|
||||
state = new_state
|
||||
|
||||
if previous_state != null:
|
||||
_exit_state(previous_state, new_state)
|
||||
if new_state != null:
|
||||
_enter_state(new_state, previous_state)
|
||||
|
||||
func add_state(state_name):
|
||||
states[states.size()] = state_name
|
||||
Loading…
Reference in New Issue
Block a user