diff --git a/behaviours/collectable.gd b/behaviours/collectable.gd index 5ef14c2..28ba596 100644 --- a/behaviours/collectable.gd +++ b/behaviours/collectable.gd @@ -1,15 +1,17 @@ -extends Node2D +extends Area2D class_name Collectable +## Emits [signal collected] when the mouse enters the given [CollisionShape2D]. + signal collected - -@export var tag: StringName +@export var qty: int = 1 +@export var tag: StringName = &"" -func _on_mouse_area_mouse_entered() -> void: +func _on_mouse_entered() -> void: collected.emit(tag) -func _on_collected(t: StringName) -> void: - Log.p(self, "Collected: %s" % t) +func _on_collected() -> void: + Log.p(self, "Collected: %sx %s" % [qty, tag]) diff --git a/behaviours/collectable.tscn b/behaviours/collectable.tscn index 70765e3..775501a 100644 --- a/behaviours/collectable.tscn +++ b/behaviours/collectable.tscn @@ -2,12 +2,8 @@ [ext_resource type="Script" path="res://behaviours/collectable.gd" id="1_p0pc3"] -[node name="Collectable" type="Node2D"] +[node name="Collectable" type="Area2D"] script = ExtResource("1_p0pc3") -[node name="MouseArea" type="Area2D" parent="."] -collision_mask = 0 -monitorable = false - [connection signal="collected" from="." to="." method="_on_collected"] -[connection signal="mouse_entered" from="MouseArea" to="." method="_on_mouse_area_mouse_entered"] +[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"]