diff --git a/objects/player/player_scholar.gd b/objects/player/player_scholar.gd index 082c844..aa938e4 100644 --- a/objects/player/player_scholar.gd +++ b/objects/player/player_scholar.gd @@ -24,7 +24,8 @@ export var jump_force: float = 150.0 export var jump_release_force: float = 0.25 ## impulse added when double jumping export var double_jump_force: float = 122.0 - +## blinking time +export var blinking_time: float = 10.0 # velocity var velocity: Vector2 = Vector2.ZERO @@ -112,6 +113,21 @@ func _on_Grounded_state_entered() -> void: snap.y = 2.5 # snap when in grounded state velocity.y = 1.0 +func _on_Still_state_entered() -> void: + animation_player.play("idle") + +func _on_Walking_state_entered() -> void: + animation_player.play("walk") + +func _on_Blinking_state_entered() -> void: + if $"%Blinking".active: + animation_player.play("blink") + var blink_timer = get_tree().create_timer(rand_range(0.2, 1.0), false) + blink_timer.connect("timeout", self,"_on_Blinking_state_entered") + +func _on_Stimming_state_entered() -> void: + animation_player.play("stim") + func _on_Pushing_state_entered() -> void: animation_player.play("push") @@ -216,9 +232,9 @@ func _process_horizontal_movement(delta: float) -> void: ## walk/idle state func _process_can_walk(delta: float) -> void: if sign(Input.get_axis("ui_left", "ui_right")) != 0.0: - animation_player.play("walk") + state_chart.send_event("walk_start") else: - animation_player.play("idle") + state_chart.send_event("walk_stop") ## rubbing up against a wall or pushing an object func _process_pushing(delta: float) -> void: diff --git a/objects/player/player_scholar.tscn b/objects/player/player_scholar.tscn index f937a81..1f59a8c 100644 --- a/objects/player/player_scholar.tscn +++ b/objects/player/player_scholar.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=39 format=2] +[gd_scene load_steps=43 format=2] [ext_resource path="res://objects/player/player_scholar.gd" type="Script" id=1] [ext_resource path="res://graphics/player/pal_purplearmor.png" type="Texture" id=2] @@ -21,6 +21,8 @@ [ext_resource path="res://graphics/player/sg_fall_scared.png" type="Texture" id=19] [ext_resource path="res://graphics/player/sg_fall.png" type="Texture" id=20] [ext_resource path="res://graphics/player/sg_push.png" type="Texture" id=21] +[ext_resource path="res://graphics/player/sg_blink.png" type="Texture" id=22] +[ext_resource path="res://graphics/player/sg_stim.png" type="Texture" id=23] [sub_resource type="ShaderMaterial" id=1] shader = ExtResource( 3 ) @@ -91,6 +93,58 @@ tracks/3/keys = { "values": [ 0.0 ] } +[sub_resource type="Animation" id=18] +resource_name = "blink" +length = 0.1 +tracks/0/type = "value" +tracks/0/path = NodePath("Graphics/Sprite:texture") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/keys = { +"times": PoolRealArray( 0 ), +"transitions": PoolRealArray( 1 ), +"update": 1, +"values": [ ExtResource( 22 ) ] +} +tracks/1/type = "value" +tracks/1/path = NodePath("Graphics/Sprite:hframes") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/keys = { +"times": PoolRealArray( 0 ), +"transitions": PoolRealArray( 1 ), +"update": 1, +"values": [ 2 ] +} +tracks/2/type = "value" +tracks/2/path = NodePath("Graphics/Sprite:frame") +tracks/2/interp = 1 +tracks/2/loop_wrap = true +tracks/2/imported = false +tracks/2/enabled = true +tracks/2/keys = { +"times": PoolRealArray( 0, 0.1 ), +"transitions": PoolRealArray( 1, 1 ), +"update": 1, +"values": [ 1, 0 ] +} +tracks/3/type = "value" +tracks/3/path = NodePath("Graphics/Sprite:rotation_degrees") +tracks/3/interp = 1 +tracks/3/loop_wrap = true +tracks/3/imported = false +tracks/3/enabled = true +tracks/3/keys = { +"times": PoolRealArray( 0 ), +"transitions": PoolRealArray( 1 ), +"update": 0, +"values": [ 0.0 ] +} + [sub_resource type="Animation" id=9] resource_name = "climb" length = 0.3 @@ -594,6 +648,60 @@ tracks/5/keys = { } ] } +[sub_resource type="Animation" id=19] +resource_name = "stim" +length = 0.3 +loop = true +step = 0.05 +tracks/0/type = "value" +tracks/0/path = NodePath("Graphics/Sprite:texture") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/keys = { +"times": PoolRealArray( 0 ), +"transitions": PoolRealArray( 1 ), +"update": 1, +"values": [ ExtResource( 23 ) ] +} +tracks/1/type = "value" +tracks/1/path = NodePath("Graphics/Sprite:hframes") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/keys = { +"times": PoolRealArray( 0 ), +"transitions": PoolRealArray( 1 ), +"update": 1, +"values": [ 2 ] +} +tracks/2/type = "value" +tracks/2/path = NodePath("Graphics/Sprite:frame") +tracks/2/interp = 1 +tracks/2/loop_wrap = true +tracks/2/imported = false +tracks/2/enabled = true +tracks/2/keys = { +"times": PoolRealArray( 0, 0.15 ), +"transitions": PoolRealArray( 1, 1 ), +"update": 1, +"values": [ 0, 1 ] +} +tracks/3/type = "value" +tracks/3/path = NodePath("Graphics/Sprite:rotation_degrees") +tracks/3/interp = 1 +tracks/3/loop_wrap = true +tracks/3/imported = false +tracks/3/enabled = true +tracks/3/keys = { +"times": PoolRealArray( 0 ), +"transitions": PoolRealArray( 1 ), +"update": 0, +"values": [ 0.0 ] +} + [sub_resource type="Animation" id=7] resource_name = "walk" length = 0.4 @@ -739,6 +847,7 @@ collide_with_bodies = false [node name="AnimationPlayer" type="AnimationPlayer" parent="."] anims/RESET = SubResource( 5 ) +anims/blink = SubResource( 18 ) anims/climb = SubResource( 9 ) anims/double_jump = SubResource( 12 ) anims/fall = SubResource( 15 ) @@ -748,6 +857,7 @@ anims/jump = SubResource( 8 ) anims/push = SubResource( 17 ) anims/shoot_airborne = SubResource( 11 ) anims/shoot_grounded = SubResource( 10 ) +anims/stim = SubResource( 19 ) anims/walk = SubResource( 7 ) [node name="StateChart" type="Node" parent="."] @@ -799,10 +909,11 @@ to = NodePath("../../Climbing") event = "ladder_touched" [node name="CanWalk" type="Node" parent="StateChart/Root/Movement/Grounded"] -script = ExtResource( 11 ) +script = ExtResource( 9 ) __meta__ = { "_editor_description_": "can walk by moving left and right" } +initial_state = NodePath("Still") [node name="On Shoot" type="Node" parent="StateChart/Root/Movement/Grounded/CanWalk"] script = ExtResource( 10 ) @@ -815,6 +926,49 @@ script = ExtResource( 10 ) to = NodePath("../../Pushing") event = "push_start" +[node name="Still" type="Node" parent="StateChart/Root/Movement/Grounded/CanWalk"] +script = ExtResource( 11 ) + +[node name="On WalkStart" type="Node" parent="StateChart/Root/Movement/Grounded/CanWalk/Still"] +script = ExtResource( 10 ) +to = NodePath("../../Walking") +event = "walk_start" + +[node name="On Timeout" type="Node" parent="StateChart/Root/Movement/Grounded/CanWalk/Still"] +script = ExtResource( 10 ) +to = NodePath("../../Blinking") +delay = 10.0 + +[node name="Walking" type="Node" parent="StateChart/Root/Movement/Grounded/CanWalk"] +script = ExtResource( 11 ) + +[node name="On WalkStop" type="Node" parent="StateChart/Root/Movement/Grounded/CanWalk/Walking"] +script = ExtResource( 10 ) +to = NodePath("../../Still") +event = "walk_stop" + +[node name="Blinking" type="Node" parent="StateChart/Root/Movement/Grounded/CanWalk"] +unique_name_in_owner = true +script = ExtResource( 11 ) + +[node name="On Timeout" type="Node" parent="StateChart/Root/Movement/Grounded/CanWalk/Blinking"] +script = ExtResource( 10 ) +to = NodePath("../../Stimming") +delay = 10.0 + +[node name="On WalkStart" type="Node" parent="StateChart/Root/Movement/Grounded/CanWalk/Blinking"] +script = ExtResource( 10 ) +to = NodePath("../../Walking") +event = "walk_start" + +[node name="Stimming" type="Node" parent="StateChart/Root/Movement/Grounded/CanWalk"] +script = ExtResource( 11 ) + +[node name="On WalkStart" type="Node" parent="StateChart/Root/Movement/Grounded/CanWalk/Stimming"] +script = ExtResource( 10 ) +to = NodePath("../../Walking") +event = "walk_start" + [node name="Shooting" type="Node" parent="StateChart/Root/Movement/Grounded"] script = ExtResource( 11 ) consumed_events = [ "jump" ] @@ -989,7 +1143,6 @@ guard_expression = "can_respawn" layer = 128 [node name="StateChartDebug" type="Tree" parent="StateDebugLayer"] -visible = false anchor_left = 1.0 anchor_right = 1.0 margin_left = -147.0 @@ -1002,15 +1155,19 @@ script = ExtResource( 8 ) [connection signal="state_physics_processing" from="StateChart/Root/Movement" to="." method="_process_movement"] [connection signal="state_entered" from="StateChart/Root/Movement/Grounded" to="." method="_on_Grounded_state_entered"] [connection signal="state_physics_processing" from="StateChart/Root/Movement/Grounded" to="." method="_process_grounded"] -[connection signal="state_physics_processing" from="StateChart/Root/Movement/Grounded/CanWalk" to="." method="_process_horizontal_movement"] [connection signal="state_physics_processing" from="StateChart/Root/Movement/Grounded/CanWalk" to="." method="_process_can_walk"] +[connection signal="state_physics_processing" from="StateChart/Root/Movement/Grounded/CanWalk" to="." method="_process_horizontal_movement"] +[connection signal="state_entered" from="StateChart/Root/Movement/Grounded/CanWalk/Still" to="." method="_on_Still_state_entered"] +[connection signal="state_entered" from="StateChart/Root/Movement/Grounded/CanWalk/Walking" to="." method="_on_Walking_state_entered"] +[connection signal="state_entered" from="StateChart/Root/Movement/Grounded/CanWalk/Blinking" to="." method="_on_Blinking_state_entered"] +[connection signal="state_entered" from="StateChart/Root/Movement/Grounded/CanWalk/Stimming" to="." method="_on_Stimming_state_entered"] [connection signal="state_entered" from="StateChart/Root/Movement/Grounded/Shooting" to="." method="_on_Shooting_state_entered"] [connection signal="state_entered" from="StateChart/Root/Movement/Grounded/Pushing" to="." method="_on_Pushing_state_entered"] [connection signal="state_physics_processing" from="StateChart/Root/Movement/Grounded/Pushing" to="." method="_process_pushing"] [connection signal="state_entered" from="StateChart/Root/Movement/Airborne" to="." method="_on_Airborne_state_entered"] [connection signal="state_physics_processing" from="StateChart/Root/Movement/Airborne" to="." method="_process_gravity"] -[connection signal="state_physics_processing" from="StateChart/Root/Movement/Airborne/Jump" to="." method="_process_jump"] [connection signal="state_physics_processing" from="StateChart/Root/Movement/Airborne/Jump" to="." method="_process_horizontal_movement"] +[connection signal="state_physics_processing" from="StateChart/Root/Movement/Airborne/Jump" to="." method="_process_jump"] [connection signal="state_entered" from="StateChart/Root/Movement/Airborne/Jump/NormalJump" to="." method="_on_NormalJump_state_entered"] [connection signal="state_exited" from="StateChart/Root/Movement/Airborne/Jump/NormalJump" to="." method="_on_NormalJump_state_exited"] [connection signal="state_entered" from="StateChart/Root/Movement/Airborne/Jump/LadderJump" to="." method="_on_LadderJump_state_entered"]