Added AbstractState and StateMachine
This commit is contained in:
@@ -3,6 +3,9 @@
|
|||||||
[ext_resource type="Script" uid="uid://bb8kc32sggrn2" path="res://game/characters/player/player.gd" id="1_xln5q"]
|
[ext_resource type="Script" uid="uid://bb8kc32sggrn2" path="res://game/characters/player/player.gd" id="1_xln5q"]
|
||||||
[ext_resource type="PackedScene" uid="uid://5qlocc0yu8ug" path="res://game/collision_switcher.tscn" id="2_j06tb"]
|
[ext_resource type="PackedScene" uid="uid://5qlocc0yu8ug" path="res://game/collision_switcher.tscn" id="2_j06tb"]
|
||||||
[ext_resource type="PackedScene" uid="uid://cvx6akiplg21s" path="res://game/characters/player/player_sprite.tscn" id="2_n6ad3"]
|
[ext_resource type="PackedScene" uid="uid://cvx6akiplg21s" path="res://game/characters/player/player_sprite.tscn" id="2_n6ad3"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://3ll3i1fgktg2" path="res://game/state_machine/state_machine.tscn" id="4_65114"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://c7adrbfobmvl8" path="res://game/state_machine/abstract_state.tscn" id="5_65114"]
|
||||||
|
[ext_resource type="Script" uid="uid://bnxccvt265hlu" path="res://game/characters/player/states/idle_state.gd" id="6_3qf5w"]
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_xln5q"]
|
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_xln5q"]
|
||||||
radius = 4.0
|
radius = 4.0
|
||||||
@@ -48,5 +51,10 @@ collision_mask = 35
|
|||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CenterArea2D" unique_id=1350886064]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="CenterArea2D" unique_id=1350886064]
|
||||||
shape = SubResource("CapsuleShape2D_t6gq4")
|
shape = SubResource("CapsuleShape2D_t6gq4")
|
||||||
|
|
||||||
|
[node name="StateMachine" parent="." unique_id=633169960 instance=ExtResource("4_65114")]
|
||||||
|
|
||||||
|
[node name="IdleState" parent="StateMachine" unique_id=739226464 instance=ExtResource("5_65114")]
|
||||||
|
script = ExtResource("6_3qf5w")
|
||||||
|
|
||||||
[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animation_finished"]
|
[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animation_finished"]
|
||||||
[connection signal="animation_looped" from="AnimatedSprite2D" to="." method="_on_animation_looped"]
|
[connection signal="animation_looped" from="AnimatedSprite2D" to="." method="_on_animation_looped"]
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
extends AbstractState
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://bnxccvt265hlu
|
||||||
@@ -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