From 4944333706f3a46e92c504044b82b3b690647b3d Mon Sep 17 00:00:00 2001 From: Lorenzo Rossi Date: Sat, 27 Apr 2024 15:32:57 +0200 Subject: [PATCH] Add sacrifical stone for sheeps & ZIndex enum --- entities/cloud.tscn | 2 +- entities/cthulhu.gd | 7 +- entities/cthulhu.tscn | 106 ++++++++++++++-------------- entities/imp.gd | 8 ++- entities/sacrifice_stone.png | 3 + entities/sacrifice_stone.png.import | 34 +++++++++ entities/sacrifice_stone.tscn | 32 +++++++++ entities/sheep.gd | 7 +- entities/sheep.tscn | 37 +++++++++- entities/watcher.gd | 8 ++- enums.gd | 10 +++ scenes/game/main_game.tscn | 9 ++- 12 files changed, 196 insertions(+), 67 deletions(-) create mode 100644 entities/sacrifice_stone.png create mode 100644 entities/sacrifice_stone.png.import create mode 100644 entities/sacrifice_stone.tscn create mode 100644 enums.gd diff --git a/entities/cloud.tscn b/entities/cloud.tscn index 28dc9d6..cd98189 100644 --- a/entities/cloud.tscn +++ b/entities/cloud.tscn @@ -2,7 +2,7 @@ [ext_resource type="Script" path="res://entities/cloud.gd" id="1_8jsek"] [ext_resource type="PackedScene" uid="uid://bc2bm8lbol18w" path="res://entities/sheep.tscn" id="3_naxi5"] -[ext_resource type="PackedScene" path="res://behaviours/spawner.tscn" id="4_0cics"] +[ext_resource type="PackedScene" uid="uid://tx1qi6ahlxjp" path="res://behaviours/spawner.tscn" id="4_0cics"] [sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_08frh"] diff --git a/entities/cthulhu.gd b/entities/cthulhu.gd index 593bdc0..780f07f 100644 --- a/entities/cthulhu.gd +++ b/entities/cthulhu.gd @@ -5,6 +5,9 @@ class_name Cthulhu @onready var sprite: SpriteLeftRight = %"Sprite" @onready var animator: AnimationPlayer = %"Animator" +func _ready(): + # Setup index and layers + _on_fallen() func _on_move(movement: Vector2): move_and_collide(movement) @@ -13,11 +16,11 @@ func _on_move(movement: Vector2): func _on_dragged(_cursor: Cursor) -> void: collision_layer = 16 collision_mask = 18 - z_index = 1 + z_index = Enums.ZIndex.EntityAir animator.play(&"drag_start") func _on_fallen() -> void: collision_layer = 8 collision_mask = 14 - z_index = 0 + z_index = Enums.ZIndex.EntityGround animator.play(&"RESET") diff --git a/entities/cthulhu.tscn b/entities/cthulhu.tscn index 737376f..b0f73fb 100644 --- a/entities/cthulhu.tscn +++ b/entities/cthulhu.tscn @@ -68,58 +68,6 @@ tracks/3/keys = { "values": [0.0] } -[sub_resource type="Animation" id="Animation_qhrn0"] -resource_name = "drag_start" -length = 0.4 -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath("SpriteFocus/Sprite:scale") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0, 0.4), -"transitions": PackedFloat32Array(1, 1), -"update": 0, -"values": [Vector2(2, 2), Vector2(2.4, 2.4)] -} -tracks/1/type = "value" -tracks/1/imported = false -tracks/1/enabled = true -tracks/1/path = NodePath("SpriteFocus/Sprite:left_texture") -tracks/1/interp = 1 -tracks/1/loop_wrap = true -tracks/1/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 1, -"values": [ExtResource("5_6ho60")] -} -tracks/2/type = "value" -tracks/2/imported = false -tracks/2/enabled = true -tracks/2/path = NodePath("SpriteFocus/Sprite:right_texture") -tracks/2/interp = 1 -tracks/2/loop_wrap = true -tracks/2/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 1, -"values": [ExtResource("6_behik")] -} -tracks/3/type = "value" -tracks/3/imported = false -tracks/3/enabled = true -tracks/3/path = NodePath("SpriteFocus:rotation") -tracks/3/interp = 1 -tracks/3/loop_wrap = true -tracks/3/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 0, -"values": [0.0] -} - [sub_resource type="Animation" id="Animation_iyn5h"] resource_name = "drag_loop" length = 2.0 @@ -173,6 +121,58 @@ tracks/3/keys = { "values": [-0.10472, 0.10472] } +[sub_resource type="Animation" id="Animation_qhrn0"] +resource_name = "drag_start" +length = 0.4 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("SpriteFocus/Sprite:scale") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 0.4), +"transitions": PackedFloat32Array(1, 1), +"update": 0, +"values": [Vector2(2, 2), Vector2(2.4, 2.4)] +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("SpriteFocus/Sprite:left_texture") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [ExtResource("5_6ho60")] +} +tracks/2/type = "value" +tracks/2/imported = false +tracks/2/enabled = true +tracks/2/path = NodePath("SpriteFocus/Sprite:right_texture") +tracks/2/interp = 1 +tracks/2/loop_wrap = true +tracks/2/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [ExtResource("6_behik")] +} +tracks/3/type = "value" +tracks/3/imported = false +tracks/3/enabled = true +tracks/3/path = NodePath("SpriteFocus:rotation") +tracks/3/interp = 1 +tracks/3/loop_wrap = true +tracks/3/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [0.0] +} + [sub_resource type="AnimationLibrary" id="AnimationLibrary_clmy5"] _data = { "RESET": SubResource("Animation_aspa2"), @@ -207,8 +207,8 @@ unique_name_in_owner = true libraries = { "": SubResource("AnimationLibrary_clmy5") } -next/drag_start = &"drag_loop" next/drag_loop = &"drag_loop" +next/drag_start = &"drag_loop" blend_times = [&"drag_start", &"drag_loop", 0.5] [node name="MovementSampler" parent="." instance=ExtResource("6_truco")] diff --git a/entities/imp.gd b/entities/imp.gd index e40bd23..6d2e79a 100644 --- a/entities/imp.gd +++ b/entities/imp.gd @@ -7,6 +7,10 @@ class_name Imp @onready var animator: AnimationPlayer = %"Animator" +func _ready(): + # Setup index and layers + _on_fallen() + func _on_move(movement: Vector2): move_and_collide(movement) sprite.handle_move(movement) @@ -17,13 +21,13 @@ func _on_eater_eaten(edible: Edible) -> void: func _on_dragged(_cursor: Cursor) -> void: collision_layer = 16 collision_mask = 18 - z_index = 1 + z_index = Enums.ZIndex.EntityAir eater.collision_mask = 16 animator.play(&"drag_start") func _on_fallen() -> void: collision_layer = 8 collision_mask = 14 - z_index = 0 + z_index = Enums.ZIndex.EntityGround eater.collision_mask = 8 animator.play(&"RESET") diff --git a/entities/sacrifice_stone.png b/entities/sacrifice_stone.png new file mode 100644 index 0000000..ac16502 --- /dev/null +++ b/entities/sacrifice_stone.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:066b0f9e6f06aedbffba3f4fc30a980327c82cc969775f7f4229a44f00180fd2 +size 510 diff --git a/entities/sacrifice_stone.png.import b/entities/sacrifice_stone.png.import new file mode 100644 index 0000000..cc15587 --- /dev/null +++ b/entities/sacrifice_stone.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://d3pn6wuykchoa" +path="res://.godot/imported/sacrifice_stone.png-0fef76a78cc081454c5c39661806c5e9.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://entities/sacrifice_stone.png" +dest_files=["res://.godot/imported/sacrifice_stone.png-0fef76a78cc081454c5c39661806c5e9.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/sacrifice_stone.tscn b/entities/sacrifice_stone.tscn new file mode 100644 index 0000000..4df3d34 --- /dev/null +++ b/entities/sacrifice_stone.tscn @@ -0,0 +1,32 @@ +[gd_scene load_steps=5 format=3 uid="uid://4xivigiybb1d"] + +[ext_resource type="PackedScene" uid="uid://dfdr3e32lohq" path="res://behaviours/edible.tscn" id="1_y58y4"] +[ext_resource type="PackedScene" uid="uid://c5pyp5hvthdof" path="res://behaviours/tracker_tracker.tscn" id="2_6m7pn"] +[ext_resource type="Texture2D" uid="uid://d3pn6wuykchoa" path="res://entities/sacrifice_stone.png" id="2_rbklw"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_yv6hf"] +radius = 0.01 + +[node name="SacrificeStone" type="Area2D"] +position = Vector2(50, 50) +collision_layer = 8 +collision_mask = 24 +monitoring = false + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("CircleShape2D_yv6hf") +one_way_collision_margin = 27.5 + +[node name="Edible" parent="." instance=ExtResource("1_y58y4")] +diet = &"Trap" + +[node name="SacrStone" parent="." instance=ExtResource("2_6m7pn")] +collision_mask = 56 + +[node name="Sprite" type="Sprite2D" parent="SacrStone"] +position = Vector2(0, 22) +texture = ExtResource("2_rbklw") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="SacrStone"] +shape = SubResource("CircleShape2D_yv6hf") +one_way_collision_margin = 27.5 diff --git a/entities/sheep.gd b/entities/sheep.gd index 41ac5c0..3b33f18 100644 --- a/entities/sheep.gd +++ b/entities/sheep.gd @@ -5,6 +5,9 @@ class_name Sheep @onready var sprite: SpriteLeftRight = %"Sprite" @onready var animator: AnimationPlayer = %"Animator" +func _ready(): + # Setup index and layers + _on_fallen() func _on_move(movement: Vector2) -> void: move_and_collide(movement) @@ -13,11 +16,11 @@ func _on_move(movement: Vector2) -> void: func _on_dragged(_cursor: Cursor) -> void: collision_layer = 16 collision_mask = 18 - z_index = 1 + z_index = Enums.ZIndex.EntityAir animator.play(&"drag_start") func _on_fallen() -> void: collision_layer = 8 collision_mask = 14 - z_index = 0 + z_index = Enums.ZIndex.EntityGround animator.play(&"RESET") diff --git a/entities/sheep.tscn b/entities/sheep.tscn index 80ba1be..1866190 100644 --- a/entities/sheep.tscn +++ b/entities/sheep.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=26 format=3 uid="uid://bc2bm8lbol18w"] +[gd_scene load_steps=29 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"] @@ -17,6 +17,7 @@ [ext_resource type="PackedScene" uid="uid://dijcjahkddudv" path="res://behaviours/draggable.tscn" id="14_0b1hs"] [ext_resource type="PackedScene" uid="uid://rx24bppccih7" path="res://behaviours/move_physics.tscn" id="14_3wojv"] [ext_resource type="PackedScene" uid="uid://c5pyp5hvthdof" path="res://behaviours/tracker_tracker.tscn" id="14_eqowb"] +[ext_resource type="PackedScene" uid="uid://ctpn4hvkhxoi3" path="res://behaviours/tracker_edible.tscn" id="16_6h84f"] [ext_resource type="AudioStream" uid="uid://bmfscpnugaejk" path="res://entities/sheep_drag.wav" id="16_nswfl"] [ext_resource type="AudioStream" uid="uid://cwsg776c11xfc" path="res://entities/fall.ogg" id="17_8kst2"] @@ -190,7 +191,14 @@ _data = { [sub_resource type="CircleShape2D" id="CircleShape2D_etpf6"] radius = 144.0 +[sub_resource type="CircleShape2D" id="CircleShape2D_nn3xr"] +radius = 25.19 + +[sub_resource type="CircleShape2D" id="CircleShape2D_bct1e"] +radius = 8.65 + [node name="Sheep" type="CharacterBody2D"] +z_index = 1 collision_layer = 8 collision_mask = 14 motion_mode = 1 @@ -277,6 +285,23 @@ debug_color = Color(1, 1, 0, 0) [node name="TargetPicker" parent="MovementRunFromHunter/HunterSense" node_paths=PackedStringArray("tracker") instance=ExtResource("13_jf6em")] tracker = NodePath("..") +[node name="MovementTrap" parent="." instance=ExtResource("12_x2g3x")] +speed = 140.0 +enabled = false + +[node name="TrapPriority" parent="MovementTrap" instance=ExtResource("11_0jlmk")] +alternative_priority = 45 + +[node name="TrackerMeat" parent="MovementTrap" instance=ExtResource("16_6h84f")] +acceptable_diets = Array[StringName]([&"Trap"]) + +[node name="Shape" type="CollisionShape2D" parent="MovementTrap/TrackerMeat"] +shape = SubResource("CircleShape2D_nn3xr") +debug_color = Color(1, 0.498039, 0, 0) + +[node name="TargetPicker" parent="MovementTrap/TrackerMeat" node_paths=PackedStringArray("tracker") instance=ExtResource("13_jf6em")] +tracker = NodePath("..") + [node name="MovementDrag" parent="." instance=ExtResource("14_3wojv")] enabled = false @@ -287,7 +312,7 @@ alternative_priority = 50 [node name="Shape" type="CollisionShape2D" parent="MovementDrag/Draggable"] scale = Vector2(3, 3) -shape = SubResource("CircleShape2D_c5tcn") +shape = SubResource("CircleShape2D_bct1e") debug_color = Color(1, 1, 1, 0) [node name="DragSound" type="AudioStreamPlayer2D" parent="MovementDrag"] @@ -316,6 +341,14 @@ stream = ExtResource("17_8kst2") [connection signal="tracked" from="MovementRunFromHunter/HunterSense" to="MovementRunFromHunter/HunterSense/TargetPicker" method="set_target_if_null"] [connection signal="untracked" from="MovementRunFromHunter/HunterSense" to="MovementRunFromHunter/HunterSense/TargetPicker" method="clear_if_target"] [connection signal="target_changed" from="MovementRunFromHunter/HunterSense/TargetPicker" to="MovementRunFromHunter" method="set_target" unbinds=1] +[connection signal="changed_target" from="MovementTrap" to="MovementTrap/TrapPriority" method="priority_conditional"] +[connection signal="move" from="MovementTrap" to="." method="_on_move"] +[connection signal="area_entered" from="MovementTrap/TrackerMeat" to="MovementTrap/TrackerMeat" method="check_diet_then_track"] +[connection signal="area_exited" from="MovementTrap/TrackerMeat" to="MovementTrap/TrackerMeat" method="untrack"] +[connection signal="tracked" from="MovementTrap/TrackerMeat" to="MovementTrap/TrackerMeat/TargetPicker" method="sample_target_if_null" unbinds=1] +[connection signal="untracked" from="MovementTrap/TrackerMeat" to="MovementTrap/TrackerMeat/TargetPicker" method="clear_if_target"] +[connection signal="target_changed" from="MovementTrap/TrackerMeat/TargetPicker" to="MovementTrap" method="set_target" unbinds=1] +[connection signal="target_changed" from="MovementTrap/TrackerMeat/TargetPicker" to="MovementTrap/TrackerMeat/TargetPicker" method="sample_target_if_null" unbinds=2] [connection signal="dragged" from="MovementDrag" to="." method="_on_dragged"] [connection signal="dragged" from="MovementDrag" to="MovementDrag/DragPriority" method="priority_alternative" unbinds=1] [connection signal="dragged" from="MovementDrag" to="MovementDrag/DragSound" method="play" unbinds=1] diff --git a/entities/watcher.gd b/entities/watcher.gd index 850f350..987b983 100644 --- a/entities/watcher.gd +++ b/entities/watcher.gd @@ -5,7 +5,9 @@ class_name Watcher @onready var sprite: SpriteLeftRight = %"Sprite" @onready var animator: AnimationPlayer = %"Animator" - +func _ready(): + # Setup index and layers + _on_fallen() func _on_move(movement: Vector2): move_and_collide(movement) @@ -14,11 +16,11 @@ func _on_move(movement: Vector2): func _on_dragged(_cursor: Cursor) -> void: collision_layer = 16 collision_mask = 18 - z_index = 1 + z_index = Enums.ZIndex.EntityAir animator.play(&"drag_start") func _on_fallen() -> void: collision_layer = 8 collision_mask = 14 - z_index = 0 + z_index = Enums.ZIndex.EntityGround animator.play(&"RESET") diff --git a/enums.gd b/enums.gd new file mode 100644 index 0000000..1e3f301 --- /dev/null +++ b/enums.gd @@ -0,0 +1,10 @@ +extends Node + +class_name Enums + +enum ZIndex { + EntityAir = 20, + EntityGround = 10, + Props = 0, + Terrain = -10, +} diff --git a/scenes/game/main_game.tscn b/scenes/game/main_game.tscn index 99f8c1e..e5310c3 100644 --- a/scenes/game/main_game.tscn +++ b/scenes/game/main_game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=21 format=3 uid="uid://cxj5aud02f40j"] +[gd_scene load_steps=22 format=3 uid="uid://cxj5aud02f40j"] [ext_resource type="Script" path="res://scenes/game/main_game.gd" id="1_wiglu"] [ext_resource type="PackedScene" uid="uid://dm068vaseh45n" path="res://scenes/game/game_camera.tscn" id="2_db5xs"] @@ -15,6 +15,7 @@ [ext_resource type="PackedScene" uid="uid://cmemgijh6nfmk" path="res://entities/chupacabra.tscn" id="11_ixo4x"] [ext_resource type="PackedScene" uid="uid://dnjtduk0hla3f" path="res://entities/watcher.tscn" id="14_8rumi"] [ext_resource type="PackedScene" uid="uid://gl4umoff474y" path="res://entities/cthulhu.tscn" id="15_k41qf"] +[ext_resource type="PackedScene" uid="uid://4xivigiybb1d" path="res://entities/sacrifice_stone.tscn" id="16_674vn"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_058kb"] texture = ExtResource("2_o7bg5") @@ -936,7 +937,7 @@ position = Vector2(-211, 241) position = Vector2(-491, 137) [node name="Sheep7" parent="." instance=ExtResource("9_qrqqu")] -position = Vector2(-177, 154) +position = Vector2(87, 40) [node name="Chupacabra" parent="." instance=ExtResource("11_ixo4x")] position = Vector2(6, -210) @@ -946,3 +947,7 @@ position = Vector2(189, 171) [node name="Cthulhu" parent="." instance=ExtResource("15_k41qf")] position = Vector2(226, -137) + +[node name="SacrificeStone" parent="." instance=ExtResource("16_674vn")] + +[editable path="SacrificeStone"]