extends Spatial

export var id_name = "default"

var rotspeed = 2

var collected

func _process(delta):
	$Sprite3D.rotation.y += rotspeed*delta
	$Sprite3D.translation.y = (sin($Sprite3D.rotation.y) - 0.5)/3
	$Particles.translation.y = $Sprite3D.translation.y


func _on_Area_body_entered(body):
	if body.is_in_group("player") and !collected:
		collected = true
		globalvar.number_beans += 1
		globalvar.beans.append(id_name)
		$Pickup.stream = load("res://sounds/SFX/collect/bean.wav")
		$Pickup.play()
		visible = false
		$Area/CollisionShape.disabled = true
		$Nearby.playing = false
		yield(get_node("Pickup"),"finished")
		queue_free()


func _ready():
	if globalvar.lookup_beans(id_name):
		queue_free()
