24 lines
685 B
GDScript
24 lines
685 B
GDScript
extends Area2D
|
|
|
|
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
|
|
@onready var collection_sound: AudioStreamPlayer2D = $CollectionSound
|
|
@onready var collision_shape_2d: CollisionShape2D = $CollisionShape2D
|
|
|
|
signal collected
|
|
|
|
func _on_body_entered(body: Node2D) -> void:
|
|
if body.name == "player":
|
|
animated_sprite_2d.animation = "collected"
|
|
# Start timer so that the apple dissapears.
|
|
collection_sound.play()
|
|
collected.emit()
|
|
call_deferred("_disable_collision")
|
|
|
|
func _disable_collision() -> void:
|
|
collision_shape_2d.disabled = true
|
|
|
|
|
|
func _on_animated_sprite_2d_animation_looped() -> void:
|
|
if animated_sprite_2d.animation == "collected":
|
|
queue_free()
|