extends "res://Flying.gd"

var fireRate = 1.3
var enemies = []
export(PackedScene) var bulletScene

func _ready():
	health = 2


func _on_Timer_timeout():
	$Timer.wait_time = fireRate
	var enemy = $DetectionArea.getCloserEnemy()
	if enemy:
		if enemy.position.x > get_viewport_rect().size.x/2:
			scale.x = 1
		else:
			scale.x = -1
	
	if(enemy != null):
		var bullet = bulletScene.instance()
		bullet.position = position
		get_parent().add_child(bullet)
		bullet.direction = (enemy.position - position).normalized()
		enemy = null

func movement(distance):
	pass

func recieveDamage(damage):
	health -= damage
	destroyBalloon()

func _on_Tower_tree_exiting():
	GameManager.addTowers()
