extends Area2D


var speed = 100
var yeetspeed = 200
var angle = 0

var invulnerable = true

var explosion = preload("res://objects/objects/explosion/Explosion.tscn")


func _process(delta):
	var dir = Vector2(cos(angle),-sin(angle))
	
	position += (dir * speed * delta)


func _on_Life_timeout():
	queue_free()


func _on_Flask_body_entered(body):
	if body.is_in_group("player"):
		if body.currentstate == body.ROLL:
			pass
		else:
			explode()
	else:
		explode()
	
	
func explode():
	if !invulnerable:
		var boom = explosion.instance()
		boom.global_position.x = global_position.x
		boom.global_position.y = global_position.y
		boom.set_damage(15)
		boom.set_color(Color(0.651268, 0.01976, 0.722656))
		get_tree().get_root().add_child(boom)
		queue_free()


func _on_Reflect_body_entered(body):
	if body.is_in_group("player"):
		if body.currentstate == body.ROLL:
			angle = -body.moveaxis.angle()
			speed = yeetspeed


func _on_SpawnTimer_timeout():
	invulnerable = false


func _on_Flask_area_entered(area):
	if area.is_in_group("sentry"):
		area.get_parent().queue_free()
		explode()
	if area.is_in_group("flask"):
		explode()
	if area.is_in_group("disposer"):
		queue_free()
