1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-25 01:24:23 +00:00

Refactor Eater and Edible

This commit is contained in:
Steffo 2024-04-15 22:43:26 +02:00
parent 97b415fabd
commit 8012c84292
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
2 changed files with 10 additions and 6 deletions

View file

@ -1,18 +1,20 @@
extends Area2D
class_name Eater
## Emits [signal eaten] whenever an [Edible] body with an acceptable [field Edible.diet] enters the given [CollisionShape2D].
signal eaten(edible: Edible)
@export var tag: StringName
@export var acceptable_diets: Array[StringName] = []
func _on_body_entered(body: Node2D) -> void:
var edibles: Array = body.find_children("Edible", "Edible", false, false)
for edible in edibles:
if edible.tag == tag:
if edible.diet in acceptable_diets:
eaten.emit(edible)
edible.eat()

View file

@ -1,13 +1,15 @@
extends Node
class_name Edible
## Emits [signal eaten] when eaten by an [Eater] whose acceptable diets contain this node's [field diet].
##
## To add multiple possible [Edible] diets to an entity, add multiple [Edible] nodes to it.
signal eaten
@export var diet: StringName = &""
func eat():
eaten.emit()
get_parent().queue_free()
@export var tag: StringName