Added AbstractState and StateMachine
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
class_name AbstractState
|
||||
extends Node
|
||||
|
||||
|
||||
@warning_ignore("unused_signal")
|
||||
signal new_state(state: AbstractState)
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
pass
|
||||
|
||||
|
||||
func exit() -> void:
|
||||
pass
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func physics_process(delta: float) -> void:
|
||||
pass
|
||||
@@ -0,0 +1 @@
|
||||
uid://ciuxe344aok4n
|
||||
@@ -0,0 +1,6 @@
|
||||
[gd_scene format=3 uid="uid://c7adrbfobmvl8"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ciuxe344aok4n" path="res://game/state_machine/abstract_state.gd" id="1_80326"]
|
||||
|
||||
[node name="AbstractState" type="Node" unique_id=739226464]
|
||||
script = ExtResource("1_80326")
|
||||
@@ -0,0 +1,22 @@
|
||||
class_name StateMachine
|
||||
extends Node
|
||||
|
||||
|
||||
var current_state : AbstractState
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if current_state:
|
||||
current_state.process(delta)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if current_state:
|
||||
current_state.physics_process(delta)
|
||||
|
||||
|
||||
func change_state(new_state: AbstractState) -> void:
|
||||
if current_state:
|
||||
current_state.exit()
|
||||
current_state = new_state
|
||||
current_state.enter()
|
||||
@@ -0,0 +1 @@
|
||||
uid://bghuevstlp4yp
|
||||
@@ -0,0 +1,6 @@
|
||||
[gd_scene format=3 uid="uid://3ll3i1fgktg2"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bghuevstlp4yp" path="res://game/state_machine/state_machine.gd" id="1_ncw1q"]
|
||||
|
||||
[node name="StateMachine" type="Node" unique_id=633169960]
|
||||
script = ExtResource("1_ncw1q")
|
||||
Reference in New Issue
Block a user