Enhanced snail entity with new features
Added a sprite to the Snail class and implemented animations for the snail's movements. The snail now has a body and shell texture, along with an eating shadow. Also, added logic to flip the sprite based on movement direction in the 'snail_eating' state. Furthermore, made CollisionShape2D invisible for better aesthetics.
This commit is contained in:
parent
7d47bdbf5a
commit
5777a7f2f1
9 changed files with 213 additions and 4 deletions
|
|
@ -1,9 +1,82 @@
|
|||
[gd_scene load_steps=6 format=3 uid="uid://bnwvtlsvxjmel"]
|
||||
[gd_scene load_steps=11 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://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
|
||||
tracks/0/path = NodePath("Sprite/SnailBody:scale")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.3, 1.5),
|
||||
"transitions": PackedFloat32Array(1, 1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector2(1, 1), Vector2(0, 0), Vector2(0, 0)]
|
||||
}
|
||||
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.1, 1, 1.1, 1.2, 1.3, 1.4, 1.5),
|
||||
"transitions": PackedFloat32Array(1, -2, 1, 1, 1, 1, 1),
|
||||
"update": 0,
|
||||
"values": [0.0, -6.28319, -6.10865, -6.28319, -6.10865, -6.28319, -6.28319]
|
||||
}
|
||||
tracks/2/type = "value"
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/path = NodePath("Sprite/SnailShell:position")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/keys = {
|
||||
"times": PackedFloat32Array(0.1, 0.6, 1, 1.5),
|
||||
"transitions": PackedFloat32Array(1, 1, 1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0, 0), Vector2(0, -300), Vector2(0, 0), Vector2(0, 0)]
|
||||
}
|
||||
tracks/3/type = "value"
|
||||
tracks/3/imported = false
|
||||
tracks/3/enabled = true
|
||||
tracks/3/path = NodePath("Sprite/SnailBody:position")
|
||||
tracks/3/interp = 1
|
||||
tracks/3/loop_wrap = true
|
||||
tracks/3/keys = {
|
||||
"times": PackedFloat32Array(0, 0.4, 0.6, 1.5),
|
||||
"transitions": PackedFloat32Array(1, 1, 1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector2(60, 30), Vector2(60, -300), Vector2(60, 30), Vector2(60, 30)]
|
||||
}
|
||||
tracks/4/type = "value"
|
||||
tracks/4/imported = false
|
||||
tracks/4/enabled = true
|
||||
tracks/4/path = NodePath("Sprite/ShadowEating:scale")
|
||||
tracks/4/interp = 1
|
||||
tracks/4/loop_wrap = true
|
||||
tracks/4/keys = {
|
||||
"times": PackedFloat32Array(0, 0.3, 1.5),
|
||||
"transitions": PackedFloat32Array(1, 1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector2(1.09451, 0.620219), Vector2(0, 0), Vector2(0, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_6ntaf"]
|
||||
_data = {
|
||||
"GoingToSleep": SubResource("Animation_kpiuy")
|
||||
}
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_2whjo"]
|
||||
radius = 42.0476
|
||||
|
|
@ -15,9 +88,32 @@ input_pickable = true
|
|||
script = ExtResource("1_lkvd1")
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
"": SubResource("AnimationLibrary_6ntaf")
|
||||
}
|
||||
autoplay = "GoingToSleep"
|
||||
|
||||
[node name="Polygon2D" type="Polygon2D" parent="."]
|
||||
polygon = PackedVector2Array(-8, -8, -5, -1, 10, 5, -7, 9, -25, 8, -28, -5, -20, -11)
|
||||
[node name="Sprite" type="Sprite2D" parent="."]
|
||||
position = Vector2(-6, 0)
|
||||
scale = Vector2(0.1, 0.1)
|
||||
|
||||
[node name="SnailBody" type="Sprite2D" parent="Sprite"]
|
||||
position = Vector2(60, 30)
|
||||
scale = Vector2(1e-05, 1e-05)
|
||||
texture = ExtResource("7_8spp3")
|
||||
|
||||
[node name="SnailShell" type="Sprite2D" parent="Sprite"]
|
||||
position = Vector2(0, -168.582)
|
||||
rotation = -4.71395
|
||||
scale = Vector2(1, 1)
|
||||
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)
|
||||
scale = Vector2(1e-05, 1e-05)
|
||||
texture = ExtResource("2_yor00")
|
||||
|
||||
[node name="StateMachine" type="Node" parent="." node_paths=PackedStringArray("initial_state")]
|
||||
script = ExtResource("1_tejvt")
|
||||
|
|
@ -30,4 +126,5 @@ script = ExtResource("3_wnrnl")
|
|||
script = ExtResource("4_1abwi")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
visible = false
|
||||
shape = SubResource("CircleShape2D_2whjo")
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ class_name Snail
|
|||
|
||||
@onready var fsm : FiniteStateMachine = $StateMachine as FiniteStateMachine
|
||||
@onready var flowers : Flowers = get_parent()
|
||||
@onready var sprite : Sprite2D = $Sprite
|
||||
|
||||
var enabled : bool = false
|
||||
var eating : bool = false
|
||||
|
|
|
|||
|
|
@ -8,12 +8,15 @@ var eat_timer : float = 0.0
|
|||
|
||||
var move_to : Vector2 = Vector2.ZERO
|
||||
|
||||
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
|
||||
|
||||
func exit() -> void:
|
||||
snail.eating = false
|
||||
snail.sprite.flip_h = false
|
||||
|
||||
func update(delta : float) -> void:
|
||||
eat_timer += delta
|
||||
|
|
@ -28,9 +31,15 @@ func physics_update(_delta : float) -> void:
|
|||
move_to = snail.get_random_target()
|
||||
|
||||
if snail.global_position.distance_to(move_to) > 3:
|
||||
|
||||
snail.velocity = snail.global_position.direction_to(move_to) * snail.speed
|
||||
|
||||
if move_to.x > snail.global_position.x:
|
||||
snail.sprite.scale.x = original_snail_scale
|
||||
else:
|
||||
snail.sprite.scale.x = -original_snail_scale
|
||||
|
||||
snail.move_and_slide()
|
||||
snail.look_at(move_to)
|
||||
else:
|
||||
move_to = Vector2.ZERO
|
||||
|
||||
|
|
|
|||
BIN
resources/textures/snail.png
Normal file
BIN
resources/textures/snail.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 110 KiB |
34
resources/textures/snail.png.import
Normal file
34
resources/textures/snail.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://dh8fo7865wgs"
|
||||
path="res://.godot/imported/snail.png-a65122e1b7cfd4a8a9eca6e69237d332.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://resources/textures/snail.png"
|
||||
dest_files=["res://.godot/imported/snail.png-a65122e1b7cfd4a8a9eca6e69237d332.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
|
||||
BIN
resources/textures/snail_body.png
Normal file
BIN
resources/textures/snail_body.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
34
resources/textures/snail_body.png.import
Normal file
34
resources/textures/snail_body.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://d30yqtob6phcj"
|
||||
path="res://.godot/imported/snail_body.png-1a9e30579365709f7ea061967bfa07c7.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://resources/textures/snail_body.png"
|
||||
dest_files=["res://.godot/imported/snail_body.png-1a9e30579365709f7ea061967bfa07c7.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
|
||||
BIN
resources/textures/snail_shell.png
Normal file
BIN
resources/textures/snail_shell.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 88 KiB |
34
resources/textures/snail_shell.png.import
Normal file
34
resources/textures/snail_shell.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://5vt8eaihmut3"
|
||||
path="res://.godot/imported/snail_shell.png-0ea323f3ee447ce81b64dbf0909411e8.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://resources/textures/snail_shell.png"
|
||||
dest_files=["res://.godot/imported/snail_shell.png-0ea323f3ee447ce81b64dbf0909411e8.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
|
||||
Loading…
Add table
Add a link
Reference in a new issue