added more sounds and autocollect coin

This commit is contained in:
Jonas Braus
2024-07-31 19:49:20 +02:00
parent 85736f82e0
commit b18dfee7dc
10 changed files with 56 additions and 8 deletions
+12 -1
View File
@@ -1,15 +1,21 @@
extends RigidBody2D
@onready var animated_sprite_2d = $AnimatedSprite2D
@export var hit_object:PackedScene
@export var auto_collect:bool
var destroyed = false
var instance = null
var _body = null
@onready var timer = $Timer
func _ready():
animated_sprite_2d.play("idle")#
func _on_activate_body_entered(body):
_body = body
if destroyed:
return
destroyed = true
animated_sprite_2d.play("destroy")
@@ -17,6 +23,11 @@ func _on_activate_body_entered(body):
if hit_object == null:
return
var instance = hit_object.instantiate()
instance = hit_object.instantiate()
add_child(instance)
instance.position.y -= 16
timer.start()
func _on_timer_timeout():
if auto_collect:
instance.collect_coin(_body)