1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-25 09:34:24 +00:00
hella-farm/behaviours/eater.gd

25 lines
581 B
GDScript3
Raw Normal View History

2024-04-15 21:50:39 +00:00
@icon("res://behaviours/eater.svg")
2024-04-14 23:23:06 +00:00
extends Area2D
class_name Eater
2024-04-15 20:43:26 +00:00
## Emits [signal eaten] whenever an [Edible] body with an acceptable [field Edible.diet] enters the given [CollisionShape2D].
2024-04-14 23:23:06 +00:00
signal eaten(edible: Edible)
2024-04-15 20:43:26 +00:00
@export var acceptable_diets: Array[StringName] = []
2024-04-14 23:23:06 +00:00
func _on_body_entered(body: Node2D) -> void:
var edibles: Array = body.find_children("Edible", "Edible", false, false)
for edible in edibles:
2024-04-15 20:43:26 +00:00
if edible.diet in acceptable_diets:
2024-04-14 23:23:06 +00:00
eaten.emit(edible)
edible.eat()
func _on_eaten(edible: Edible) -> void:
Log.p(self, "Eaten: %s" % edible)