1
Fork 0
mirror of https://github.com/Steffo99/swear-jar.git synced 2024-11-25 09:04:19 +00:00
swear-jar/collector/universal_collector.gd

31 lines
846 B
GDScript3
Raw Normal View History

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:
var collectible: Collectible = body.find_child("Collectible")
if collectible:
collected_count += 1
collectible.collect()
collected.emit(body)
2023-10-02 01:33:41 +00:00
if collected_count >= collecting_amount:
goal.emit()
2023-10-02 01:33:41 +00:00
collected_count = 0