diff --git a/entities/Snail.tscn b/entities/Snail.tscn index 3c65461..3f6e78d 100644 --- a/entities/Snail.tscn +++ b/entities/Snail.tscn @@ -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") diff --git a/entities/scripts/snail.gd b/entities/scripts/snail.gd index 491e152..02106fb 100644 --- a/entities/scripts/snail.gd +++ b/entities/scripts/snail.gd @@ -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 diff --git a/entities/snail/states/snail_eating.gd b/entities/snail/states/snail_eating.gd index de749f6..6908201 100644 --- a/entities/snail/states/snail_eating.gd +++ b/entities/snail/states/snail_eating.gd @@ -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 diff --git a/resources/textures/snail.png b/resources/textures/snail.png new file mode 100644 index 0000000..75b47bd Binary files /dev/null and b/resources/textures/snail.png differ diff --git a/resources/textures/snail.png.import b/resources/textures/snail.png.import new file mode 100644 index 0000000..e0d511d --- /dev/null +++ b/resources/textures/snail.png.import @@ -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 diff --git a/resources/textures/snail_body.png b/resources/textures/snail_body.png new file mode 100644 index 0000000..ce1dffb Binary files /dev/null and b/resources/textures/snail_body.png differ diff --git a/resources/textures/snail_body.png.import b/resources/textures/snail_body.png.import new file mode 100644 index 0000000..5162f68 --- /dev/null +++ b/resources/textures/snail_body.png.import @@ -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 diff --git a/resources/textures/snail_shell.png b/resources/textures/snail_shell.png new file mode 100644 index 0000000..ceedfa6 Binary files /dev/null and b/resources/textures/snail_shell.png differ diff --git a/resources/textures/snail_shell.png.import b/resources/textures/snail_shell.png.import new file mode 100644 index 0000000..6052301 --- /dev/null +++ b/resources/textures/snail_shell.png.import @@ -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