extends CharacterBody2D

@export_enum("color", "red", "blue", "green", "black") var type : int = 3
var is_good : bool = true

func _ready() -> void:
	velocity = Vector2.from_angle(randf() * PI * 2) * 25
	match type:
		0: modulate = Color.RED
		1: modulate = Color.BLUE
		2: modulate = Color.GREEN	

func _process(delta: float) -> void:
	var results = move_and_collide(velocity * delta, false)
	if results != null:
		velocity = velocity.reflect(Vector2.from_angle(results.get_angle()))

func vibrate() -> void:
	$Sprite2D.offset = Vector2((randf() - .5) * 2, (randf() - .5) * 2) * 1

func remove(delay:int) -> void:
	if is_good:
		$AnimationPlayer.play("GoodGrab")
	else:
		$AnimationPlayer.play("BadGrab")
	
	await get_tree().create_timer(delay * 0.1).timeout
	
	if is_good:
		get_parent().get_node("PopSound").play()
	else:
		get_parent().get_node("OomfSound").play()
	get_tree().queue_delete(self)
