Fixed crystal signal

This commit is contained in:
theskywinds 2025-05-18 15:55:49 +02:00
parent 7a2f860519
commit d19ddcb23b
3 changed files with 22 additions and 9 deletions

View File

@ -1,14 +1,16 @@
extends Area2D extends Area2D
signal _picked_up signal crystal_picked_up
func _ready(): func _ready():
add_to_group("crystals") add_to_group("crystals")
print("ready") print("ready")
func _on_body_entered(body: Node2D) -> void: func _on_body_entered(body: Node2D) -> void:
add_user_signal("_picked_up") if body.name == "player":
emit_signal("_picked_up") print("Player entered")
self.queue_free() emit_signal("crystal_picked_up")
print("meow") queue_free()
else:
print("Whoops, something went wrong")

View File

@ -21,8 +21,16 @@ collision_enabled = false
[node name="player" parent="." instance=ExtResource("2_r1egm")] [node name="player" parent="." instance=ExtResource("2_r1egm")]
position = Vector2(373, 125) position = Vector2(373, 125)
[node name="collectableCrystal" parent="." instance=ExtResource("3_56573")]
position = Vector2(401, 240)
[node name="rock" parent="." instance=ExtResource("4_1l7e8")] [node name="rock" parent="." instance=ExtResource("4_1l7e8")]
position = Vector2(498, 169) position = Vector2(498, 169)
[node name="Node2D" type="Node2D" parent="."]
position = Vector2(304, 494)
[node name="Area2D2" parent="Node2D" instance=ExtResource("3_56573")]
[node name="Area2D" parent="Node2D" instance=ExtResource("3_56573")]
position = Vector2(87, -71)
[node name="collectableCrystal" parent="Node2D" instance=ExtResource("3_56573")]
position = Vector2(97, -254)

View File

@ -2,9 +2,12 @@ extends CharacterBody2D
const SPEED = 3.0 const SPEED = 3.0
func _ready() -> void: func _ready() -> void:
await get_tree().process_frame
var crystals = get_tree().get_nodes_in_group("crystals") var crystals = get_tree().get_nodes_in_group("crystals")
print("Got " + str(crystals.size()) + " crystals")
for crystal in crystals: for crystal in crystals:
crystal.connect("_picked_up", Callable(self, "collect")) print("Connecting crystal: " + crystal.name)
crystal.connect("crystal_picked_up", Callable(self, "collect"))
func collect(): func collect():
print("something") print("something")