first iteration with authorative movement
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
extends Node
|
||||
|
||||
@export var starting_state: State
|
||||
|
||||
var current_state: State
|
||||
|
||||
func init(subject: Node) -> void:
|
||||
for state in get_children():
|
||||
state.subject = subject
|
||||
|
||||
_change_state(starting_state)
|
||||
|
||||
func _change_state(new_state: State) -> void:
|
||||
if current_state:
|
||||
current_state.exit()
|
||||
|
||||
current_state = new_state
|
||||
current_state.enter()
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var new_state = current_state.process_physics(delta)
|
||||
if new_state:
|
||||
_change_state(new_state)
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
var new_state = current_state.process_input(event)
|
||||
if new_state:
|
||||
_change_state(new_state)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var new_state = current_state.process_frame(delta)
|
||||
if new_state:
|
||||
_change_state(new_state)
|
||||
Reference in New Issue
Block a user