From b8f42a552ecb61d81dbafb9f5fda5d9722e4091c Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 16 May 2024 12:00:52 +0100 Subject: [PATCH] Enhanced snail animations and interactions Added new animation states for the snail entity, including 'Move' and 'Sleep'. The snail now hides certain elements when eating and plays appropriate animations when transitioning between states. Also introduced a new texture for sleep indication. --- entities/Snail.tscn | 223 +++++++++++++++++++++++- entities/scripts/snail.gd | 14 +- entities/snail/states/snail_eating.gd | 4 + entities/snail/states/snail_sleeping.gd | 2 + resources/textures/z.png | Bin 0 -> 3018 bytes resources/textures/z.png.import | 34 ++++ 6 files changed, 268 insertions(+), 9 deletions(-) create mode 100644 resources/textures/z.png create mode 100644 resources/textures/z.png.import diff --git a/entities/Snail.tscn b/entities/Snail.tscn index 3f6e78d..7c064d0 100644 --- a/entities/Snail.tscn +++ b/entities/Snail.tscn @@ -1,17 +1,17 @@ -[gd_scene load_steps=11 format=3 uid="uid://bnwvtlsvxjmel"] +[gd_scene load_steps=14 format=3 uid="uid://bnwvtlsvxjmel"] [ext_resource type="Script" path="res://entities/scripts/snail.gd" id="1_lkvd1"] [ext_resource type="Script" path="res://entities/scripts/finite_state_machine.gd" id="1_tejvt"] [ext_resource type="Texture2D" uid="uid://dh8fo7865wgs" path="res://resources/textures/snail.png" id="2_yor00"] [ext_resource type="Script" path="res://entities/snail/states/snail_sleeping.gd" id="3_wnrnl"] [ext_resource type="Script" path="res://entities/snail/states/snail_eating.gd" id="4_1abwi"] +[ext_resource type="Texture2D" uid="uid://coqnsy2doe00a" path="res://resources/textures/z.png" id="5_owmpd"] [ext_resource type="Texture2D" uid="uid://d30yqtob6phcj" path="res://resources/textures/snail_body.png" id="7_8spp3"] [ext_resource type="Texture2D" uid="uid://5vt8eaihmut3" path="res://resources/textures/snail_shell.png" id="8_0v3d4"] [sub_resource type="Animation" id="Animation_kpiuy"] resource_name = "GoingToSleep" length = 1.5 -loop_mode = 1 tracks/0/type = "value" tracks/0/imported = false tracks/0/enabled = true @@ -72,10 +72,189 @@ tracks/4/keys = { "update": 0, "values": [Vector2(1.09451, 0.620219), Vector2(0, 0), Vector2(0, 0)] } +tracks/5/type = "value" +tracks/5/imported = false +tracks/5/enabled = true +tracks/5/path = NodePath("Sprite/ShadowShell:scale") +tracks/5/interp = 1 +tracks/5/loop_wrap = true +tracks/5/keys = { +"times": PackedFloat32Array(0, 0.3, 1, 1.5), +"transitions": PackedFloat32Array(1, 1, 1, 1), +"update": 0, +"values": [Vector2(1.002, 0.3), Vector2(0.8, 0.3), Vector2(1.002, 0.3), Vector2(1.002, 0.3)] +} +tracks/6/type = "value" +tracks/6/imported = false +tracks/6/enabled = true +tracks/6/path = NodePath("Sprite/ShadowShell:visible") +tracks/6/interp = 1 +tracks/6/loop_wrap = true +tracks/6/keys = { +"times": PackedFloat32Array(0, 1.5), +"transitions": PackedFloat32Array(1, 1), +"update": 1, +"values": [true, true] +} + +[sub_resource type="Animation" id="Animation_w6m82"] +resource_name = "Move" +loop_mode = 1 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("Sprite/SnailBody:scale") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 0.5, 1), +"transitions": PackedFloat32Array(1, 1, 1), +"update": 0, +"values": [Vector2(1, 1), Vector2(1.08, 1), Vector2(1, 1)] +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("Sprite/SnailShell:rotation") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0, 0.5, 1), +"transitions": PackedFloat32Array(1, 1, 1), +"update": 0, +"values": [0.0, -0.0523599, 0.0] +} +tracks/2/type = "value" +tracks/2/imported = false +tracks/2/enabled = true +tracks/2/path = NodePath("Sprite/SnailBody:visible") +tracks/2/interp = 1 +tracks/2/loop_wrap = true +tracks/2/keys = { +"times": PackedFloat32Array(0, 1), +"transitions": PackedFloat32Array(1, 1), +"update": 1, +"values": [true, true] +} +tracks/3/type = "value" +tracks/3/imported = false +tracks/3/enabled = true +tracks/3/path = NodePath("Sprite/ShadowEating:scale") +tracks/3/interp = 1 +tracks/3/loop_wrap = true +tracks/3/keys = { +"times": PackedFloat32Array(0, 0.5, 1), +"transitions": PackedFloat32Array(1, 1, 1), +"update": 0, +"values": [Vector2(1, 1), Vector2(1.08, 1), Vector2(1, 1)] +} + +[sub_resource type="Animation" id="Animation_oua3i"] +resource_name = "Sleep" +length = 4.0 +loop_mode = 1 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("Sprite/SnailBody:visible") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 4), +"transitions": PackedFloat32Array(1, 1), +"update": 1, +"values": [false, false] +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("Sprite/SnailShell:scale") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4), +"transitions": PackedFloat32Array(-2, -2, -2, -2, -2, -2, -2, -2, -2), +"update": 0, +"values": [Vector2(1, 1), Vector2(1.01, 1.01), Vector2(1, 1), Vector2(1.01, 1.01), Vector2(1, 1), Vector2(1.01, 1.01), Vector2(1, 1), Vector2(1.01, 1.01), Vector2(1, 1)] +} +tracks/2/type = "value" +tracks/2/imported = false +tracks/2/enabled = true +tracks/2/path = NodePath("Z:visible") +tracks/2/interp = 1 +tracks/2/loop_wrap = true +tracks/2/keys = { +"times": PackedFloat32Array(0, 4), +"transitions": PackedFloat32Array(1, 1), +"update": 1, +"values": [true, false] +} +tracks/3/type = "value" +tracks/3/imported = false +tracks/3/enabled = true +tracks/3/path = NodePath("Z:modulate") +tracks/3/interp = 1 +tracks/3/loop_wrap = true +tracks/3/keys = { +"times": PackedFloat32Array(0, 0.2, 0.3, 1.2, 1.3, 4), +"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1), +"update": 0, +"values": [Color(1, 1, 1, 0), Color(1, 1, 1, 0), Color(1, 1, 1, 1), Color(1, 1, 1, 1), Color(1, 1, 1, 0), Color(1, 1, 1, 0)] +} +tracks/4/type = "value" +tracks/4/imported = false +tracks/4/enabled = true +tracks/4/path = NodePath("Z2:visible") +tracks/4/interp = 1 +tracks/4/loop_wrap = true +tracks/4/keys = { +"times": PackedFloat32Array(0, 4), +"transitions": PackedFloat32Array(1, 1), +"update": 1, +"values": [true, false] +} +tracks/5/type = "value" +tracks/5/imported = false +tracks/5/enabled = true +tracks/5/path = NodePath("Z2:modulate") +tracks/5/interp = 1 +tracks/5/loop_wrap = true +tracks/5/keys = { +"times": PackedFloat32Array(0, 0.4, 0.5, 1.4, 1.5, 4), +"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1), +"update": 0, +"values": [Color(1, 1, 1, 0), Color(1, 1, 1, 0), Color(1, 1, 1, 1), Color(1, 1, 1, 0.885714), Color(1, 1, 1, 0), Color(1, 1, 1, 0)] +} +tracks/6/type = "value" +tracks/6/imported = false +tracks/6/enabled = true +tracks/6/path = NodePath("Z3:visible") +tracks/6/interp = 1 +tracks/6/loop_wrap = true +tracks/6/keys = { +"times": PackedFloat32Array(0, 4), +"transitions": PackedFloat32Array(1, 1), +"update": 1, +"values": [true, false] +} +tracks/7/type = "value" +tracks/7/imported = false +tracks/7/enabled = true +tracks/7/path = NodePath("Z3:modulate") +tracks/7/interp = 1 +tracks/7/loop_wrap = true +tracks/7/keys = { +"times": PackedFloat32Array(0, 0.6, 0.7, 1.7, 1.8, 4), +"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1), +"update": 0, +"values": [Color(1, 1, 1, 0), Color(1, 1, 1, 0), Color(1, 1, 1, 0.992157), Color(1, 1, 1, 1), Color(1, 1, 1, 0), Color(1, 1, 1, 0)] +} [sub_resource type="AnimationLibrary" id="AnimationLibrary_6ntaf"] _data = { -"GoingToSleep": SubResource("Animation_kpiuy") +"GoingToSleep": SubResource("Animation_kpiuy"), +"Move": SubResource("Animation_w6m82"), +"Sleep": SubResource("Animation_oua3i") } [sub_resource type="CircleShape2D" id="CircleShape2D_2whjo"] @@ -91,7 +270,29 @@ script = ExtResource("1_lkvd1") libraries = { "": SubResource("AnimationLibrary_6ntaf") } -autoplay = "GoingToSleep" +autoplay = "Move" + +[node name="Z" type="Sprite2D" parent="."] +visible = false +position = Vector2(-17, -22) +scale = Vector2(0.1, 0.1) +texture = ExtResource("5_owmpd") + +[node name="Z2" type="Sprite2D" parent="."] +visible = false +modulate = Color(1, 1, 1, 0.958931) +position = Vector2(-12, -38) +rotation = 0.464258 +scale = Vector2(0.11, 0.11) +texture = ExtResource("5_owmpd") + +[node name="Z3" type="Sprite2D" parent="."] +visible = false +modulate = Color(1, 1, 1, 0.993125) +position = Vector2(-30, -47) +rotation = -0.205949 +scale = Vector2(0.13, 0.13) +texture = ExtResource("5_owmpd") [node name="Sprite" type="Sprite2D" parent="."] position = Vector2(-6, 0) @@ -102,16 +303,22 @@ position = Vector2(60, 30) scale = Vector2(1e-05, 1e-05) texture = ExtResource("7_8spp3") +[node name="ShadowShell" type="Sprite2D" parent="Sprite"] +self_modulate = Color(0, 0, 0, 0.0784314) +position = Vector2(10, 130) +rotation = -0.00998773 +scale = Vector2(1.002, 0.3) +texture = ExtResource("8_0v3d4") + [node name="SnailShell" type="Sprite2D" parent="Sprite"] -position = Vector2(0, -168.582) -rotation = -4.71395 -scale = Vector2(1, 1) +rotation = -6.28319 +scale = Vector2(1.00249, 1.00249) texture = ExtResource("8_0v3d4") [node name="ShadowEating" type="Sprite2D" parent="Sprite"] self_modulate = Color(0, 0, 0, 0.0784314) show_behind_parent = true -position = Vector2(121, 68.925) +position = Vector2(60, 20) scale = Vector2(1e-05, 1e-05) texture = ExtResource("2_yor00") diff --git a/entities/scripts/snail.gd b/entities/scripts/snail.gd index 02106fb..72ead40 100644 --- a/entities/scripts/snail.gd +++ b/entities/scripts/snail.gd @@ -4,6 +4,7 @@ class_name Snail @onready var fsm : FiniteStateMachine = $StateMachine as FiniteStateMachine @onready var flowers : Flowers = get_parent() @onready var sprite : Sprite2D = $Sprite +@onready var animation : AnimationPlayer = $AnimationPlayer var enabled : bool = false var eating : bool = false @@ -13,6 +14,7 @@ var mouse_over : bool = false func _ready() -> void: connect("mouse_entered", Callable(self, "on_mouse_entered")) connect("mouse_exited", Callable(self, "on_mouse_exited")) + animation.connect("animation_finished", Callable(self, "on_animation_finished")) # Detect mouse left click and trigger function func _input(event : InputEvent) -> void: @@ -27,6 +29,12 @@ func eat() -> void: # Reduce the GameState flower_nectar_level GameState.flower_nectar_level -= 1 +func hide_zeds() -> void: + $Z.hide() + $Z2.hide() + $Z3.hide() + $Sprite/ShadowShell.hide() + func maybe_sleep() -> void: # If the snail is still eating, then we want a 30% chance of switching it it to the sleeping state if eating: @@ -46,4 +54,8 @@ func on_mouse_entered() -> void: func on_mouse_exited() -> void: # Reset the cursor to the default mouse_over = false - CursorMgr.reset_cursor() \ No newline at end of file + CursorMgr.reset_cursor() + +func on_animation_finished(anim_name : StringName) -> void: + if anim_name == "GoingToSleep": + animation.play("Sleep") \ No newline at end of file diff --git a/entities/snail/states/snail_eating.gd b/entities/snail/states/snail_eating.gd index 6908201..1efbe33 100644 --- a/entities/snail/states/snail_eating.gd +++ b/entities/snail/states/snail_eating.gd @@ -13,6 +13,10 @@ var original_snail_scale : float = 0.1 func enter(_msg : Dictionary = {}) -> void: Log.pr("I am a snail and I will eat!") snail.eating = true + if snail.animation: + snail.animation.play("Move") + + snail.hide_zeds() func exit() -> void: snail.eating = false diff --git a/entities/snail/states/snail_sleeping.gd b/entities/snail/states/snail_sleeping.gd index f47363d..13b0156 100644 --- a/entities/snail/states/snail_sleeping.gd +++ b/entities/snail/states/snail_sleeping.gd @@ -9,6 +9,8 @@ var sleep_timer : float = 0 func enter(_msg : Dictionary = {}) -> void: Log.pr("I am a snail asleep...") snail.rotation = 0 + if snail.animation: + snail.animation.play("GoingToSleep") CursorMgr.reset_cursor() # Decide how many seconds until the snail wakes up again diff --git a/resources/textures/z.png b/resources/textures/z.png new file mode 100644 index 0000000000000000000000000000000000000000..fca60d2f7fcbc5625d6747f6bd047853274ee27f GIT binary patch literal 3018 zcmV;*3pMnKP)RCr$Poq4R)#TCaziA$BbQ3b74ao4(Ub*bXMi&aalrml@z z;+Cjs{~#`ZG{)G*VA{Awh2Tas#0@v9PYc>=MX)O1F0=xoh>E+_e!kE7y%PYdw0&vIp_O3Gru{r4Op%}wY9*OL$}|aOeaEnKtrJ~pjptQS@UMx(zbva zGYqJ)ZttrG*tHSz0_gM>!V2h%0eYH`3iSir2P%MjDnE^eR!ITe$K*L4kY7%bx6&*F zE3GYn%AD8!1yT3OAnp&z`$y=Q3_O)&U7?a%0;vRWk4Mz&pr0BgQohEoaGe8zIqcSNaNZv(>rArp0(_b z02puu?Ag%jSq)^!|CWKLG?u6V23U}e zuqO*<3Yd76f(0006;>PtX$4@f8p#nos|Efk+(9oOaNn$qmb;kkgt)YSCMTjhQBqX1xKXJ*DPDJ<~~Pp z<*=p#*gff5*R)?bV&pDWVZzA(n{_;DeS7|t`X0(Hbp-{q1sHHIL5{O3kR@vs@4}$B z;t2pdCo400?Fi4Htb8v26F!f98+GavU<{zmSK7{@y|F%}zah*W7&xy7hBavd;nk<7bKVU1@Sdxc&Z>7N-w4dU>Bs&ZuL3?{)xg0 zM5teV0@5ye?Wiv-q3e$+Y+qx6cN_U?VQci@>uUt}JL*<2;yGv1o7*$mWQ~}xrpmjEN z)`fagLwS2n@EnNuuE`%|zbWg@_b!a{U_}p7pVgr6?))g7Eor=ksZJhwuyrP-o!r`l zrIijE(rAj#m!xQ%C27}!mkaCCG|?7?`{J3;4}UU5m5P+1RaplbD|*GqS1X%5_|1YO zm`gdg1MD>gl~;H%E_$_rv0$$bS4peGKmhp|#WgIkj(@e`S#zzormeKbd|F{*O+id9 zEUR2{2+K`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