From 56a39892e04243c9f83f885d213e85909f32c07c Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Fri, 26 Apr 2024 01:19:27 +0200 Subject: [PATCH] Add sheep drag animation Co-authored-by: Maxim Lobovsky --- behaviours/sprite_left_right.gd | 10 +++- entities/sheep.tscn | 77 +++++++++++++++++++++++++++- entities/sheep_drag_left.png | 3 ++ entities/sheep_drag_left.png.import | 34 ++++++++++++ entities/sheep_drag_right.png | 3 ++ entities/sheep_drag_right.png.import | 34 ++++++++++++ entities/sheep_left.png | 4 +- entities/sheep_right.png | 4 +- 8 files changed, 162 insertions(+), 7 deletions(-) create mode 100644 entities/sheep_drag_left.png create mode 100644 entities/sheep_drag_left.png.import create mode 100644 entities/sheep_drag_right.png create mode 100644 entities/sheep_drag_right.png.import diff --git a/behaviours/sprite_left_right.gd b/behaviours/sprite_left_right.gd index 74287ca..3186ae1 100644 --- a/behaviours/sprite_left_right.gd +++ b/behaviours/sprite_left_right.gd @@ -5,9 +5,15 @@ class_name SpriteLeftRight @export var left_texture: Texture2D @export var right_texture: Texture2D +var last_discrim: float = 0 func handle_move(movement: Vector2): - if movement.x > 0: + var discrim = movement.x + if discrim == 0: + discrim = last_discrim + if discrim > 0: texture = right_texture - elif movement.x < 0: + last_discrim = discrim + elif discrim < 0: texture = left_texture + last_discrim = discrim diff --git a/entities/sheep.tscn b/entities/sheep.tscn index 5efa344..a0e5076 100644 --- a/entities/sheep.tscn +++ b/entities/sheep.tscn @@ -1,10 +1,12 @@ -[gd_scene load_steps=24 format=3 uid="uid://bc2bm8lbol18w"] +[gd_scene load_steps=26 format=3 uid="uid://bc2bm8lbol18w"] [ext_resource type="Script" path="res://entities/sheep.gd" id="1_4dmll"] [ext_resource type="Texture2D" uid="uid://iljp5yn3ehfk" path="res://entities/sheep_left.png" id="2_t13f5"] [ext_resource type="PackedScene" uid="uid://bxbjfev0lhwws" path="res://behaviours/sprite_left_right.tscn" id="2_xbkrm"] [ext_resource type="Texture2D" uid="uid://cxtmas4g0v6en" path="res://entities/sheep_right.png" id="4_5qoof"] +[ext_resource type="Texture2D" uid="uid://cfduc7cdorasr" path="res://entities/sheep_drag_left.png" id="5_gh6h6"] [ext_resource type="PackedScene" uid="uid://dfdr3e32lohq" path="res://behaviours/edible.tscn" id="6_3odsh"] +[ext_resource type="Texture2D" uid="uid://m5bebwb06kqe" path="res://entities/sheep_drag_right.png" id="6_x4fsj"] [ext_resource type="PackedScene" uid="uid://djcwis8ycrq85" path="res://behaviours/sampler_priority.tscn" id="9_s5lod"] [ext_resource type="PackedScene" uid="uid://dk1ipq7dhkhf3" path="res://behaviours/move_straight.tscn" id="10_05kcd"] [ext_resource type="PackedScene" uid="uid://cm67ko1k6kn4u" path="res://behaviours/priority.tscn" id="11_0jlmk"] @@ -47,6 +49,30 @@ tracks/1/keys = { "update": 0, "values": [0.0] } +tracks/2/type = "value" +tracks/2/imported = false +tracks/2/enabled = true +tracks/2/path = NodePath("Sprite:left_texture") +tracks/2/interp = 1 +tracks/2/loop_wrap = true +tracks/2/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [ExtResource("2_t13f5")] +} +tracks/3/type = "value" +tracks/3/imported = false +tracks/3/enabled = true +tracks/3/path = NodePath("Sprite:right_texture") +tracks/3/interp = 1 +tracks/3/loop_wrap = true +tracks/3/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [ExtResource("4_5qoof")] +} [sub_resource type="Animation" id="Animation_5yt72"] resource_name = "drag_loop" @@ -76,6 +102,30 @@ tracks/1/keys = { "update": 0, "values": [0.0] } +tracks/2/type = "value" +tracks/2/imported = false +tracks/2/enabled = true +tracks/2/path = NodePath("Sprite:left_texture") +tracks/2/interp = 1 +tracks/2/loop_wrap = true +tracks/2/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [ExtResource("5_gh6h6")] +} +tracks/3/type = "value" +tracks/3/imported = false +tracks/3/enabled = true +tracks/3/path = NodePath("Sprite:right_texture") +tracks/3/interp = 1 +tracks/3/loop_wrap = true +tracks/3/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [ExtResource("6_x4fsj")] +} [sub_resource type="Animation" id="Animation_2igbw"] resource_name = "drag_start" @@ -104,6 +154,30 @@ tracks/1/keys = { "update": 0, "values": [0.0] } +tracks/2/type = "value" +tracks/2/imported = false +tracks/2/enabled = true +tracks/2/path = NodePath("Sprite:left_texture") +tracks/2/interp = 1 +tracks/2/loop_wrap = true +tracks/2/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [ExtResource("5_gh6h6")] +} +tracks/3/type = "value" +tracks/3/imported = false +tracks/3/enabled = true +tracks/3/path = NodePath("Sprite:right_texture") +tracks/3/interp = 1 +tracks/3/loop_wrap = true +tracks/3/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [ExtResource("6_x4fsj")] +} [sub_resource type="AnimationLibrary" id="AnimationLibrary_6mutq"] _data = { @@ -122,6 +196,7 @@ motion_mode = 1 script = ExtResource("1_4dmll") [node name="Sprite" parent="." instance=ExtResource("2_xbkrm")] +position = Vector2(0, -4) scale = Vector2(2, 2) texture = ExtResource("2_t13f5") left_texture = ExtResource("2_t13f5") diff --git a/entities/sheep_drag_left.png b/entities/sheep_drag_left.png new file mode 100644 index 0000000..641da31 --- /dev/null +++ b/entities/sheep_drag_left.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cd2c6f056364d0b7306396804906688c7e9dec52d096c74d01ae07f9de17211e +size 1109 diff --git a/entities/sheep_drag_left.png.import b/entities/sheep_drag_left.png.import new file mode 100644 index 0000000..b66d558 --- /dev/null +++ b/entities/sheep_drag_left.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cfduc7cdorasr" +path="res://.godot/imported/sheep_drag_left.png-a7c04bb39da88d0f0854bbdfbabc6662.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://entities/sheep_drag_left.png" +dest_files=["res://.godot/imported/sheep_drag_left.png-a7c04bb39da88d0f0854bbdfbabc6662.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/entities/sheep_drag_right.png b/entities/sheep_drag_right.png new file mode 100644 index 0000000..6d73f8c --- /dev/null +++ b/entities/sheep_drag_right.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7887a5318e9b80756a2f55d7a84e87781f9b5f1ee4852861b75420da96afd325 +size 1068 diff --git a/entities/sheep_drag_right.png.import b/entities/sheep_drag_right.png.import new file mode 100644 index 0000000..d548635 --- /dev/null +++ b/entities/sheep_drag_right.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://m5bebwb06kqe" +path="res://.godot/imported/sheep_drag_right.png-3946842e67ee30d62560fdb07c61bedb.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://entities/sheep_drag_right.png" +dest_files=["res://.godot/imported/sheep_drag_right.png-3946842e67ee30d62560fdb07c61bedb.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/entities/sheep_left.png b/entities/sheep_left.png index 1a65cce..c549a50 100644 --- a/entities/sheep_left.png +++ b/entities/sheep_left.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c095f5a6d0cb477db9b103ce58a1533bf56764d652a25a4ca53949d27e66e660 -size 581 +oid sha256:ccb62220b665b12984b0f497e35c4e3ebf3816bda7f0a162e39f1e8b7acb463e +size 1053 diff --git a/entities/sheep_right.png b/entities/sheep_right.png index 14b0ac5..0ec017a 100644 --- a/entities/sheep_right.png +++ b/entities/sheep_right.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5eed0c320958ff7f25a391d6be285b616c8da89ee2833d58fff79a1171852c69 -size 562 +oid sha256:245a19a61461568e5d55560d683da7879e5302d142ecd18b98bbe8f2fd6d6a20 +size 1029