[gd_scene load_steps=28 format=3 uid="uid://v5vg88it87oj"]

[ext_resource type="Script" path="res://godot_state_charts_examples/platformer/ninja_frog/ninja_frog.gd" id="1_xi1lh"]
[ext_resource type="Script" path="res://addons/godot_state_charts/state_chart.gd" id="3_qw75p"]
[ext_resource type="Script" path="res://addons/godot_state_charts/compound_state.gd" id="4_g6c55"]
[ext_resource type="Script" path="res://addons/godot_state_charts/atomic_state.gd" id="6_vmkuk"]
[ext_resource type="Texture2D" uid="uid://bgswg1pgd01d1" path="res://godot_state_charts_examples/platformer/ninja_frog/full.png" id="7_fehuj"]
[ext_resource type="Script" path="res://addons/godot_state_charts/transition.gd" id="9_wswdv"]

[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_1ethx"]
radius = 12.0

[sub_resource type="Animation" id="Animation_uq0h4"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 0
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [0]
}

[sub_resource type="Animation" id="Animation_10ku2"]
resource_name = "double_jump"
length = 0.4
step = 0.05
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.4),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [23, 28]
}

[sub_resource type="Animation" id="Animation_ibg22"]
resource_name = "fall"
length = 0.1
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [29]
}

[sub_resource type="Animation" id="Animation_5rh2e"]
resource_name = "idle"
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 1),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [12, 22]
}

[sub_resource type="Animation" id="Animation_jaga7"]
resource_name = "jump"
length = 0.1
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [30]
}

[sub_resource type="Animation" id="Animation_6odvc"]
resource_name = "walk"
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 1),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [0, 11]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_au2ov"]
_data = {
"RESET": SubResource("Animation_uq0h4"),
"double_jump": SubResource("Animation_10ku2"),
"fall": SubResource("Animation_ibg22"),
"idle": SubResource("Animation_5rh2e"),
"jump": SubResource("Animation_jaga7"),
"walk": SubResource("Animation_6odvc")
}

[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_k3ia7"]
animation = &"double_jump"

[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_iie7f"]
animation = &"idle"

[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_oetyn"]
animation = &"jump"

[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_gw83y"]
animation = &"walk"

[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_iq3nb"]
animation = &"fall"

[sub_resource type="AnimationNodeBlendSpace1D" id="AnimationNodeBlendSpace1D_o7w1c"]
blend_point_0/node = SubResource("AnimationNodeAnimation_oetyn")
blend_point_0/pos = -1.0
blend_point_1/node = SubResource("AnimationNodeAnimation_gw83y")
blend_point_1/pos = 0.0
blend_point_2/node = SubResource("AnimationNodeAnimation_iq3nb")
blend_point_2/pos = 1.0
blend_mode = 1

[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_i3ow4"]
advance_mode = 2

[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_a52qu"]

[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_1q7sj"]

[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_4cnci"]

[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_ddbej"]
switch_mode = 2
advance_mode = 2

[sub_resource type="AnimationNodeStateMachine" id="AnimationNodeStateMachine_ckafx"]
states/DoubleJump/node = SubResource("AnimationNodeAnimation_k3ia7")
states/DoubleJump/position = Vector2(767.5, 63.4141)
states/End/position = Vector2(962, 49)
states/Idle/node = SubResource("AnimationNodeAnimation_iie7f")
states/Idle/position = Vector2(342.5, 63.625)
states/Move/node = SubResource("AnimationNodeBlendSpace1D_o7w1c")
states/Move/position = Vector2(575.5, 62.7813)
states/Start/position = Vector2(210.5, 73.75)
transitions = ["Start", "Idle", SubResource("AnimationNodeStateMachineTransition_i3ow4"), "Idle", "Move", SubResource("AnimationNodeStateMachineTransition_a52qu"), "Move", "Idle", SubResource("AnimationNodeStateMachineTransition_1q7sj"), "Move", "DoubleJump", SubResource("AnimationNodeStateMachineTransition_4cnci"), "DoubleJump", "Move", SubResource("AnimationNodeStateMachineTransition_ddbej")]
graph_offset = Vector2(84, -7)

[sub_resource type="AnimationNodeStateMachinePlayback" id="AnimationNodeStateMachinePlayback_63x7j"]

[node name="NinjaFrog" type="CharacterBody2D" groups=["player"]]
input_pickable = true
script = ExtResource("1_xi1lh")

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, -15)
shape = SubResource("CapsuleShape2D_1ethx")

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_au2ov")
}

[node name="Sprite" type="Sprite2D" parent="."]
texture_filter = 1
texture = ExtResource("7_fehuj")
offset = Vector2(0, -12)
hframes = 31

[node name="AnimationTree" type="AnimationTree" parent="."]
tree_root = SubResource("AnimationNodeStateMachine_ckafx")
anim_player = NodePath("../AnimationPlayer")
active = true
process_callback = 0
parameters/playback = SubResource("AnimationNodeStateMachinePlayback_63x7j")
parameters/Move/blend_position = -0.380028

[node name="StateChart" type="Node" parent="."]
script = ExtResource("3_qw75p")
track_in_editor = true

[node name="Root" type="Node" parent="StateChart"]
editor_description = "This is the root of all movement related states."
script = ExtResource("4_g6c55")
initial_state = NodePath("Grounded")

[node name="Grounded" type="Node" parent="StateChart/Root"]
editor_description = "This state is active when the player is on the ground."
script = ExtResource("6_vmkuk")

[node name="On Jump" type="Node" parent="StateChart/Root/Grounded"]
editor_description = "When jumping become airborne and enable double-jump."
script = ExtResource("9_wswdv")
to = NodePath("../../Airborne/DoubleJumpEnabled")
event = &"jump"
delay_in_seconds = "0.0"

[node name="On Airborne" type="Node" parent="StateChart/Root/Grounded"]
editor_description = "When becoming airborne (e.g. through falling) move to airborne state."
script = ExtResource("9_wswdv")
to = NodePath("../../Airborne")
event = &"airborne"
delay_in_seconds = "0.0"

[node name="Airborne" type="Node" parent="StateChart/Root"]
editor_description = "This is the root state for when the player is in the air. We have sub-states to handle the various input that is allowed when in the air."
script = ExtResource("4_g6c55")
initial_state = NodePath("CoyoteJumpEnabled")

[node name="On Grounded" type="Node" parent="StateChart/Root/Airborne"]
script = ExtResource("9_wswdv")
to = NodePath("../../Grounded")
event = &"grounded"
delay_in_seconds = "0.0"

[node name="CoyoteJumpEnabled" type="Node" parent="StateChart/Root/Airborne"]
editor_description = "While in this state, the player can jump for a short time. The state is activated by default when the player becomes airborne from falling. Allowing a jump for a short time makes the controls feel nicer. The \"On Expiration\" transition will leave this state after the grace period."
script = ExtResource("6_vmkuk")

[node name="On Jump" type="Node" parent="StateChart/Root/Airborne/CoyoteJumpEnabled"]
editor_description = "On jump handle this as if the player originally jumped."
script = ExtResource("9_wswdv")
to = NodePath("../../DoubleJumpEnabled")
event = &"jump"
delay_in_seconds = "0.0"

[node name="On Expiration" type="Node" parent="StateChart/Root/Airborne/CoyoteJumpEnabled"]
editor_description = "After 0.2 seconds automatically move to falling state where no more jump is possible."
script = ExtResource("9_wswdv")
to = NodePath("../../CannotJump")
delay_in_seconds = "0.2"

[node name="DoubleJumpEnabled" type="Node" parent="StateChart/Root/Airborne"]
editor_description = "This state is active while the player is in the air and has jumped one time already. While the state is active, a second jump is allowed."
script = ExtResource("6_vmkuk")

[node name="On Jump" type="Node" parent="StateChart/Root/Airborne/DoubleJumpEnabled"]
editor_description = "When jumping in double jump state, move to a state where no more jumps are possible.

Triggers the double-jump animation as a side effect."
script = ExtResource("9_wswdv")
to = NodePath("../../CannotJump")
event = &"jump"
delay_in_seconds = "0.0"

[node name="CannotJump" type="Node" parent="StateChart/Root/Airborne"]
editor_description = "This state is active when the player is airborne but can no longer jump either because the coyote-jump grace period has expired or the player has already used the double-jump."
script = ExtResource("6_vmkuk")

[connection signal="input_event" from="." to="." method="_on_input_event"]
[connection signal="state_physics_processing" from="StateChart/Root/Grounded" to="." method="_on_jump_enabled_state_physics_processing"]
[connection signal="state_physics_processing" from="StateChart/Root/Airborne/CoyoteJumpEnabled" to="." method="_on_jump_enabled_state_physics_processing"]
[connection signal="state_physics_processing" from="StateChart/Root/Airborne/DoubleJumpEnabled" to="." method="_on_jump_enabled_state_physics_processing"]
[connection signal="taken" from="StateChart/Root/Airborne/DoubleJumpEnabled/On Jump" to="." method="_on_double_jump_jump"]
