From c0055761a4e7d9149f1f337fc93e20e72029a4a9 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 13 Apr 2024 23:27:36 +0200 Subject: [PATCH] Create `Collectible` behaviour based on @snowycoder's `Gold` entity --- behaviours/collectable.gd | 15 +++++++++++++++ behaviours/collectable.tscn | 14 ++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 behaviours/collectable.gd create mode 100644 behaviours/collectable.tscn diff --git a/behaviours/collectable.gd b/behaviours/collectable.gd new file mode 100644 index 0000000..ec79ced --- /dev/null +++ b/behaviours/collectable.gd @@ -0,0 +1,15 @@ +extends Node2D +class_name Collectable + + +@export var tag: StringName + + +signal collected(tag: StringName) + + +func _on_mouse_area_mouse_entered() -> void: + collected.emit() + +func _on_collected(t: StringName) -> void: + Log.p(self, "Collected: %s" % t) diff --git a/behaviours/collectable.tscn b/behaviours/collectable.tscn new file mode 100644 index 0000000..9b2a0ea --- /dev/null +++ b/behaviours/collectable.tscn @@ -0,0 +1,14 @@ +[gd_scene load_steps=3 format=3 uid="uid://dj72yshd25ucx"] + +[ext_resource type="Script" path="res://behaviours/collectable.gd" id="1_p0pc3"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_su28r"] +radius = 16.4012 + +[node name="Collectable" type="Node2D"] +script = ExtResource("1_p0pc3") + +[node name="CollectArea" type="Area2D" parent="."] + +[node name="Shape" type="CollisionShape2D" parent="CollectArea"] +shape = SubResource("CircleShape2D_su28r")