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

Make Collectable an Area2D

This commit is contained in:
Steffo 2024-04-15 22:39:06 +02:00
parent c12df50328
commit 85d487a56c
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
2 changed files with 10 additions and 12 deletions

View file

@ -1,15 +1,17 @@
extends Node2D extends Area2D
class_name Collectable class_name Collectable
## Emits [signal collected] when the mouse enters the given [CollisionShape2D].
signal collected signal collected
@export var qty: int = 1
@export var tag: StringName @export var tag: StringName = &""
func _on_mouse_area_mouse_entered() -> void: func _on_mouse_entered() -> void:
collected.emit(tag) collected.emit(tag)
func _on_collected(t: StringName) -> void: func _on_collected() -> void:
Log.p(self, "Collected: %s" % t) Log.p(self, "Collected: %sx %s" % [qty, tag])

View file

@ -2,12 +2,8 @@
[ext_resource type="Script" path="res://behaviours/collectable.gd" id="1_p0pc3"] [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") 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="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"]