1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-21 15:44:23 +00:00

Make watcher eat stuff that's being dragged

This commit is contained in:
Steffo 2024-04-30 04:49:00 +02:00
parent 229fc6f992
commit 4ddb1a36a7
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
4 changed files with 57 additions and 15 deletions

View file

@ -1,10 +1,7 @@
[gd_scene load_steps=4 format=3 uid="uid://db246fkcf452d"] [gd_scene load_steps=3 format=3 uid="uid://db246fkcf452d"]
[ext_resource type="Texture2D" uid="uid://13au54xlwvd8" path="res://entities/tree1.png" id="1_yk0t0"] [ext_resource type="Texture2D" uid="uid://13au54xlwvd8" path="res://entities/tree1.png" id="1_yk0t0"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_rvj5w"]
size = Vector2(36, 36)
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_0arkv"] [sub_resource type="CapsuleShape2D" id="CapsuleShape2D_0arkv"]
radius = 34.5 radius = 34.5
height = 91.0 height = 91.0
@ -18,14 +15,6 @@ position = Vector2(0, -48)
scale = Vector2(2, 2) scale = Vector2(2, 2)
texture = ExtResource("1_yk0t0") texture = ExtResource("1_yk0t0")
[node name="Lower" type="StaticBody2D" parent="."]
collision_layer = 8
collision_mask = 0
[node name="Shape" type="CollisionShape2D" parent="Lower"]
position = Vector2(0, -8)
shape = SubResource("RectangleShape2D_rvj5w")
[node name="Upper" type="StaticBody2D" parent="."] [node name="Upper" type="StaticBody2D" parent="."]
collision_layer = 16 collision_layer = 16
collision_mask = 0 collision_mask = 0

View file

@ -26,3 +26,6 @@ func _on_trapped() -> void:
func _on_freed() -> void: func _on_freed() -> void:
z_index = Enums.ZIndex.EntityAir z_index = Enums.ZIndex.EntityAir
y_sort_enabled = true y_sort_enabled = true
func _on_eater_eaten(edible: Edible) -> void:
edible.get_parent().queue_free()

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=26 format=3 uid="uid://dnjtduk0hla3f"] [gd_scene load_steps=30 format=3 uid="uid://dnjtduk0hla3f"]
[ext_resource type="Script" path="res://entities/watcher.gd" id="1_brahc"] [ext_resource type="Script" path="res://entities/watcher.gd" id="1_brahc"]
[ext_resource type="PackedScene" uid="uid://bxbjfev0lhwws" path="res://behaviours/sprite_left_right.tscn" id="1_thu73"] [ext_resource type="PackedScene" uid="uid://bxbjfev0lhwws" path="res://behaviours/sprite_left_right.tscn" id="1_thu73"]
@ -18,6 +18,8 @@
[ext_resource type="PackedScene" uid="uid://cml7rqvyfuagx" path="res://behaviours/move_towards.tscn" id="14_qtr50"] [ext_resource type="PackedScene" uid="uid://cml7rqvyfuagx" path="res://behaviours/move_towards.tscn" id="14_qtr50"]
[ext_resource type="PackedScene" uid="uid://ctpn4hvkhxoi3" path="res://behaviours/tracker_edible.tscn" id="15_ihnef"] [ext_resource type="PackedScene" uid="uid://ctpn4hvkhxoi3" path="res://behaviours/tracker_edible.tscn" id="15_ihnef"]
[ext_resource type="PackedScene" uid="uid://dti7l0d40hhgt" path="res://behaviours/target_picker.tscn" id="16_ch04y"] [ext_resource type="PackedScene" uid="uid://dti7l0d40hhgt" path="res://behaviours/target_picker.tscn" id="16_ch04y"]
[ext_resource type="PackedScene" uid="uid://jg7qkbswgqjc" path="res://behaviours/eater.tscn" id="19_ktenf"]
[ext_resource type="AudioStream" uid="uid://c1yuksnjdd6g2" path="res://entities/imp_eat.ogg" id="20_bdcer"]
[sub_resource type="CircleShape2D" id="CircleShape2D_diig7"] [sub_resource type="CircleShape2D" id="CircleShape2D_diig7"]
radius = 32.0 radius = 32.0
@ -152,9 +154,15 @@ _data = {
[sub_resource type="CircleShape2D" id="CircleShape2D_a0gfn"] [sub_resource type="CircleShape2D" id="CircleShape2D_a0gfn"]
radius = 25.19 radius = 25.19
[sub_resource type="CircleShape2D" id="CircleShape2D_w03iw"]
radius = 256.0
[sub_resource type="CircleShape2D" id="CircleShape2D_ywwo3"] [sub_resource type="CircleShape2D" id="CircleShape2D_ywwo3"]
radius = 32.0 radius = 32.0
[sub_resource type="CircleShape2D" id="CircleShape2D_3tmg0"]
radius = 40.0
[node name="Watcher" type="CharacterBody2D"] [node name="Watcher" type="CharacterBody2D"]
z_index = 10 z_index = 10
collision_layer = 16 collision_layer = 16
@ -218,6 +226,24 @@ debug_color = Color(1, 0.498039, 0, 0)
[node name="TargetPicker" parent="MovementTrap/TrackerTrap" node_paths=PackedStringArray("tracker") instance=ExtResource("16_ch04y")] [node name="TargetPicker" parent="MovementTrap/TrackerTrap" node_paths=PackedStringArray("tracker") instance=ExtResource("16_ch04y")]
tracker = NodePath("..") tracker = NodePath("..")
[node name="MovementHunt" parent="." instance=ExtResource("14_qtr50")]
speed = 300.0
enabled = false
[node name="HuntPriority" parent="MovementHunt" instance=ExtResource("9_wtsor")]
alternative_priority = 40
[node name="TrackerMeat" parent="MovementHunt" instance=ExtResource("15_ihnef")]
collision_mask = 48
acceptable_diets = Array[StringName]([&"Meat"])
[node name="Shape" type="CollisionShape2D" parent="MovementHunt/TrackerMeat"]
shape = SubResource("CircleShape2D_w03iw")
debug_color = Color(1, 0.498039, 0, 0)
[node name="TargetPicker" parent="MovementHunt/TrackerMeat" node_paths=PackedStringArray("tracker") instance=ExtResource("16_ch04y")]
tracker = NodePath("..")
[node name="MovementDrag" parent="." instance=ExtResource("8_jy8ay")] [node name="MovementDrag" parent="." instance=ExtResource("8_jy8ay")]
position = Vector2(1, 0) position = Vector2(1, 0)
enabled = false enabled = false
@ -239,6 +265,19 @@ bus = &"DragSounds"
stream = ExtResource("12_0h21e") stream = ExtResource("12_0h21e")
bus = &"FallSounds" bus = &"FallSounds"
[node name="Eater" parent="." instance=ExtResource("19_ktenf")]
unique_name_in_owner = true
collision_mask = 16
acceptable_diets = Array[StringName]([&"Meat"])
[node name="Shape" type="CollisionShape2D" parent="Eater"]
shape = SubResource("CircleShape2D_3tmg0")
debug_color = Color(1, 0, 0, 0)
[node name="EatSound" type="AudioStreamPlayer2D" parent="Eater"]
stream = ExtResource("20_bdcer")
bus = &"KillSounds"
[connection signal="sacrificed" from="Sacrificable" to="." method="queue_free"] [connection signal="sacrificed" from="Sacrificable" to="." method="queue_free"]
[connection signal="move" from="MovementTilt" to="." method="_on_move"] [connection signal="move" from="MovementTilt" to="." method="_on_move"]
[connection signal="ready" from="MovementTilt" to="MovementTilt" method="randomize_direction"] [connection signal="ready" from="MovementTilt" to="MovementTilt" method="randomize_direction"]
@ -254,6 +293,12 @@ bus = &"FallSounds"
[connection signal="untracked" from="MovementTrap/TrackerTrap" to="MovementTrap/TrackerTrap/TargetPicker" method="clear_if_target"] [connection signal="untracked" from="MovementTrap/TrackerTrap" to="MovementTrap/TrackerTrap/TargetPicker" method="clear_if_target"]
[connection signal="target_changed" from="MovementTrap/TrackerTrap/TargetPicker" to="MovementTrap" method="set_target" unbinds=1] [connection signal="target_changed" from="MovementTrap/TrackerTrap/TargetPicker" to="MovementTrap" method="set_target" unbinds=1]
[connection signal="target_changed" from="MovementTrap/TrackerTrap/TargetPicker" to="MovementTrap/TrackerTrap/TargetPicker" method="sample_target_if_null" unbinds=2] [connection signal="target_changed" from="MovementTrap/TrackerTrap/TargetPicker" to="MovementTrap/TrackerTrap/TargetPicker" method="sample_target_if_null" unbinds=2]
[connection signal="changed_target" from="MovementHunt" to="MovementHunt/HuntPriority" method="priority_conditional"]
[connection signal="move" from="MovementHunt" to="." method="_on_move"]
[connection signal="tracked" from="MovementHunt/TrackerMeat" to="MovementHunt/TrackerMeat/TargetPicker" method="sample_target_if_null" unbinds=1]
[connection signal="untracked" from="MovementHunt/TrackerMeat" to="MovementHunt/TrackerMeat/TargetPicker" method="clear_if_target"]
[connection signal="target_changed" from="MovementHunt/TrackerMeat/TargetPicker" to="MovementHunt" method="set_target" unbinds=1]
[connection signal="target_changed" from="MovementHunt/TrackerMeat/TargetPicker" to="MovementHunt/TrackerMeat/TargetPicker" method="sample_target_if_null" unbinds=2]
[connection signal="dragged" from="MovementDrag" to="." method="_on_dragged"] [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/DragPriority" method="priority_alternative" unbinds=1]
[connection signal="dragged" from="MovementDrag" to="MovementDrag/DragSound" method="play" unbinds=1] [connection signal="dragged" from="MovementDrag" to="MovementDrag/DragSound" method="play" unbinds=1]
@ -263,3 +308,5 @@ bus = &"FallSounds"
[connection signal="move" from="MovementDrag" to="." method="_on_move"] [connection signal="move" from="MovementDrag" to="." method="_on_move"]
[connection signal="dragged" from="MovementDrag/Draggable" to="MovementDrag" method="drag"] [connection signal="dragged" from="MovementDrag/Draggable" to="MovementDrag" method="drag"]
[connection signal="dropped" from="MovementDrag/Draggable" to="MovementDrag" method="drop"] [connection signal="dropped" from="MovementDrag/Draggable" to="MovementDrag" method="drop"]
[connection signal="eaten" from="Eater" to="." method="_on_eater_eaten"]
[connection signal="eaten" from="Eater" to="Eater/EatSound" method="play" unbinds=1]

View file

@ -48,8 +48,11 @@ func drop():
if dragging: if dragging:
var target = dragging var target = dragging
dragging = null dragging = null
target.drop() if is_instance_valid(target):
dropped.emit(target) target.drop()
dropped.emit(target)
else:
dropped.emit(null)
func log_dragging() -> void: func log_dragging() -> void:
Log.p(self, "Dragging: %s" % dragging) Log.p(self, "Dragging: %s" % dragging)