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.
This commit is contained in:
Dan 2024-05-16 12:00:52 +01:00
parent 5777a7f2f1
commit b8f42a552e
6 changed files with 268 additions and 9 deletions

View file

@ -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")

View file

@ -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:
@ -47,3 +55,7 @@ func on_mouse_exited() -> void:
# Reset the cursor to the default
mouse_over = false
CursorMgr.reset_cursor()
func on_animation_finished(anim_name : StringName) -> void:
if anim_name == "GoingToSleep":
animation.play("Sleep")

View file

@ -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

View file

@ -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

BIN
resources/textures/z.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://coqnsy2doe00a"
path="res://.godot/imported/z.png-2480fe672c962580156c436c995706d3.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://resources/textures/z.png"
dest_files=["res://.godot/imported/z.png-2480fe672c962580156c436c995706d3.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1