Files
godot-demo-projects/2d/finite_state_machine/Demo.tscn
Yaxian 1d8fa9c44d Add player_state dictionary to manage player state names for FSM demo (#1143)
* Add player_state dictionary to manage player state names for FSM demo

* Use a constant typed Dictionary of StringNames and update to Godot 4.5

---------

Co-authored-by: Aaron Franke <arnfranke@yahoo.com>
2025-10-01 21:33:27 -07:00

89 lines
2.9 KiB
Plaintext

[gd_scene load_steps=9 format=3 uid="uid://dmn8nkpogiwsf"]
[ext_resource type="PackedScene" uid="uid://bpdyvy2681m3i" path="res://player/Player.tscn" id="1"]
[ext_resource type="FontFile" uid="uid://b5bspum6ffekd" path="res://fonts/SourceCodePro-Bold.ttf" id="2_r1c5f"]
[ext_resource type="PackedScene" uid="uid://cvi13chv8g4hj" path="res://debug/StatesStackDiplayer.tscn" id="3"]
[ext_resource type="PackedScene" uid="uid://bq6rrfy53rfvo" path="res://debug/ControlsPanel.tscn" id="4"]
[sub_resource type="Animation" id="1"]
[sub_resource type="Animation" id="2"]
length = 0.6
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("BodyPivot/Body:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.4),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1),
"update": 0,
"values": [Color(1, 1, 1, 1), Color(1, 0, 0, 1), Color(1, 1, 1, 1), Color(1, 0, 0, 1), Color(1, 1, 1, 1), Color(1, 0, 0, 1), Color(1, 1, 1, 1)]
}
[sub_resource type="Animation" id="3"]
[sub_resource type="AnimationLibrary" id="AnimationLibrary_qbwwp"]
_data = {
&"idle": SubResource("1"),
&"stagger": SubResource("2"),
&"walk": SubResource("3")
}
[node name="Demo" type="Node"]
[node name="Player" parent="." instance=ExtResource("1")]
position = Vector2(640, 400)
[node name="StateMachine" parent="Player" index="0"]
start_state = NodePath("Idle")
[node name="AnimationPlayer" parent="Player" index="1"]
libraries = {
&"": SubResource("AnimationLibrary_qbwwp")
}
[node name="StateNameDisplayer" parent="Player" index="5"]
physics_interpolation_mode = 1
theme_override_fonts/font = ExtResource("2_r1c5f")
[node name="Explanations" type="RichTextLabel" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 10.0
offset_top = -370.0
offset_right = -10.0
offset_bottom = -730.0
grow_horizontal = 2
grow_vertical = 2
size_flags_vertical = 4
mouse_filter = 2
bbcode_enabled = true
text = "This example shows how to apply the State programming pattern in GDScript, including Hierarchical States, and a pushdown automaton.
States are common in games. You can use the pattern to:
1. Separate each behavior and transitions between behaviors, thus make scripts shorter and easier to manage.
2. Respect the Single Responsibility Principle. Each State object represents one action.
3. Improve your code's structure. Look at the scene tree and FileSystem tab: without looking at the code, you'll know what the Player can or cannot do.
You can read more about States in the excellent Game Programming Patterns ebook."
[node name="Control" type="Control" parent="."]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="StatesStackDiplayer" parent="Control" instance=ExtResource("3")]
layout_mode = 0
[node name="ControlsPanel" parent="Control" instance=ExtResource("4")]
layout_mode = 1
[editable path="Player"]