extends "res://scripts/enemy.gd"

var dir = Vector2()
var pos_x = 0
var offset = 0
var amplitude = 30
var period = 10

func _process(delta):
	var offset = sin(range_lerp(position.y, 0, 240, 0, period)) * amplitude
	rotation_degrees = stepify(offset, 16)
	position.y += dir.y * speed * delta
	position.x = pos_x + offset 
	
func death():
	var e = get_parent().explossion_scene.instance()
	e.position = position
	get_tree().root.add_child(e)
	global.game.get_node("bg/anim").play("explossion")
	global.change_score(score_bonus)
	get_parent()._on_enemy_death(1)
	queue_free()

func _on_enemy_1_area_entered(area):
	if area.name == "home":
		escape()
	elif area.name == "player":
		if area.shield == false:
			area.death()
		else:
			death()
		return
	else:
		death()
	
func escape():
	get_parent()._on_enemy_escape()
	
func _ready():
	dir = Vector2(0, 1)
