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

39 lines
851 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-30 03:17:57 +00:00
## Emitted when the [field goal] number of entities has been eaten.
signal goal_reached
2024-04-14 23:23:06 +00:00
2024-04-15 20:43:26 +00:00
@export var acceptable_diets: Array[StringName] = []
2024-04-14 23:23:06 +00:00
2024-04-30 03:17:57 +00:00
@export var target = -1
## Count of how many times something was eaten.
var count: int = 0
2024-04-14 23:23:06 +00:00
2024-04-19 01:39:07 +00:00
func log_eaten(edible: Edible) -> void:
Log.p(self, "Eaten: %s" % edible)
2024-05-01 04:26:30 +00:00
func plus_one():
count += 1
if count == target:
goal_reached.emit()
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()
2024-05-01 04:26:30 +00:00
plus_one()