Fixed crystal signal
This commit is contained in:
parent
7a2f860519
commit
d19ddcb23b
|
@ -1,14 +1,16 @@
|
|||
extends Area2D
|
||||
|
||||
signal _picked_up
|
||||
signal crystal_picked_up
|
||||
|
||||
func _ready():
|
||||
add_to_group("crystals")
|
||||
print("ready")
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
add_user_signal("_picked_up")
|
||||
emit_signal("_picked_up")
|
||||
self.queue_free()
|
||||
print("meow")
|
||||
if body.name == "player":
|
||||
print("Player entered")
|
||||
emit_signal("crystal_picked_up")
|
||||
queue_free()
|
||||
else:
|
||||
print("Whoops, something went wrong")
|
||||
|
||||
|
|
|
@ -21,8 +21,16 @@ collision_enabled = false
|
|||
[node name="player" parent="." instance=ExtResource("2_r1egm")]
|
||||
position = Vector2(373, 125)
|
||||
|
||||
[node name="collectableCrystal" parent="." instance=ExtResource("3_56573")]
|
||||
position = Vector2(401, 240)
|
||||
|
||||
[node name="rock" parent="." instance=ExtResource("4_1l7e8")]
|
||||
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)
|
||||
|
|
|
@ -2,9 +2,12 @@ extends CharacterBody2D
|
|||
|
||||
const SPEED = 3.0
|
||||
func _ready() -> void:
|
||||
await get_tree().process_frame
|
||||
var crystals = get_tree().get_nodes_in_group("crystals")
|
||||
print("Got " + str(crystals.size()) + " 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():
|
||||
print("something")
|
||||
|
|
Loading…
Reference in New Issue
Block a user