bovido/scripts/state_machine.gd
Mathilde Grapin 7038d29d87 First commit
Add simple player movement with a finite state machine.
Add enemy that can move to target point.
Add ground through a tilemap and wall that player and enemy cannot
cross.
2023-06-11 23:38:54 +02:00

35 lines
661 B
GDScript

class_name StateMachine
extends Node
signal transitioned(state_name)
@export var state: State
func _ready():
await owner.ready
for child in get_children():
child.state_machine = self
state.enter()
func _unhandled_input(event):
state.handle_input(event)
func _process(delta):
state.update(delta)
func _physics_process(delta):
state.physics_update(delta)
func transition_to(target_state_name: String, msg: Dictionary = {}):
if not has_node(target_state_name):
push_warning("No state with name " + target_state_name)
return
state.exit()
state = get_node(target_state_name)
state.enter(msg)
emit_signal("transitioned", state.name)