mirror of
https://github.com/Steffo99/hella-farm.git
synced 2024-11-21 15:44:23 +00:00
Refactor Eater
and Edible
This commit is contained in:
parent
97b415fabd
commit
8012c84292
2 changed files with 10 additions and 6 deletions
|
@ -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()
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue