extends Area2D


export var bonus_name = ""

var type = "bonus"
var y =0
var new_y = 0
var collected = false
var speed = 2

func _process(delta):
	new_y += speed * delta
	if ceil(y) != ceil(new_y):
		y = new_y
		position.y += 1
		
func collect():
	if !collected:
		$life_time.disconnect("timeout", self, "queue_free")
		collected = true
		$sprite.visible = false
		$collect.play()
		yield($collect,"finished")
		queue_free()
		
func _ready():
	if bonus_name == "support":
		$sprite.frame = 0
	elif bonus_name == "rockets":
		$sprite.frame = 1
	elif bonus_name == "hp":
		$sprite.frame = 2
	elif bonus_name == "fuel":
		$sprite.frame = 3
		speed = 16
	var _err = $life_time.connect("timeout", self, "queue_free")
