2023-10-02 01:33:41 +00:00
|
|
|
extends Area2D
|
|
|
|
class_name UniversalCollector
|
|
|
|
## Area that will pick up all [Collectible]s which enter inside it.
|
|
|
|
|
|
|
|
|
|
|
|
## The current amount of collected entities.
|
|
|
|
var collected_count: int = 0
|
|
|
|
|
|
|
|
## The goal amount of entities to collect.
|
|
|
|
##
|
|
|
|
## When [collected_count] reaches it, it will be reset to zero, and the "goal" signal will be emitted.
|
|
|
|
@export var collecting_amount: int
|
|
|
|
|
|
|
|
## The collector has picked up an object.
|
|
|
|
signal collected(body: PhysicsBody2D)
|
|
|
|
|
|
|
|
## The collector has received its collection goal and is about to reset.
|
|
|
|
signal goal
|
|
|
|
|
|
|
|
|
|
|
|
func _on_body_entered(body: Node2D):
|
|
|
|
if body is PhysicsBody2D:
|
2023-10-03 00:13:20 +00:00
|
|
|
print("[UniversalCollector] Body entered: ", body)
|
2023-10-02 01:33:41 +00:00
|
|
|
var collectible: Collectible = body.find_child("Collectible")
|
|
|
|
if collectible:
|
|
|
|
collected_count += 1
|
|
|
|
collectible.collect()
|
2023-10-02 23:48:59 +00:00
|
|
|
collected.emit(body)
|
2023-10-02 01:33:41 +00:00
|
|
|
if collected_count >= collecting_amount:
|
2023-10-02 23:48:59 +00:00
|
|
|
goal.emit()
|
2023-10-02 01:33:41 +00:00
|
|
|
collected_count = 0
|