1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2025-02-16 09:03:58 +00:00

Create Hunter behaviour, tracking Edible bodies inside a certain area

This commit is contained in:
Steffo 2024-04-13 23:56:22 +02:00
parent 1738ad0ed0
commit 630eb88f22
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
2 changed files with 35 additions and 0 deletions

24
behaviours/hunter.gd Normal file
View file

@ -0,0 +1,24 @@
extends Node2D
class_name Hunter
signal tracked(body: Node2D)
signal untracked(body: Node2D)
@export var tag: StringName
var possible_targets: Array = []
func _on_detection_area_body_entered(body: Node2D) -> void:
if body.find_children("Edible", "Edible", false, false):
Log.p(self, "Tracking a new target: %s" % body)
possible_targets.push_back(body)
tracked.emit(body)
func _on_detection_area_body_exited(body: Node2D) -> void:
if body in possible_targets:
Log.p(self, "Not tracking anymore target: %s" % body)
possible_targets.erase(body)
untracked.emit(body)

11
behaviours/hunter.tscn Normal file
View file

@ -0,0 +1,11 @@
[gd_scene load_steps=2 format=3 uid="uid://ctpn4hvkhxoi3"]
[sub_resource type="CircleShape2D" id="CircleShape2D_kxb8e"]
radius = 100.0
[node name="Hunter" type="Node2D"]
[node name="DetectionArea" type="Area2D" parent="."]
[node name="Shape" type="CollisionShape2D" parent="DetectionArea"]
shape = SubResource("CircleShape2D_kxb8e")