extends Area2D

export (float) var rate_of_fire = 1

var name = "poop"
var atack = false
var player = null
var projectile_scene = null

onready var timer = get_node("timer")

func _process(delta):
	var dist = get_global_pos().distance_to(player.get_global_pos())
	if !atack and dist < 100:
		atack((player.get_global_pos().x - get_global_pos().x) *1.4)
		
func atack(x):
	atack = true
	var projectile = projectile_scene.instance()
	projectile.set_global_pos(get_global_pos())
	projectile.velocity.x = x
	get_parent().add_child(projectile)
	get_node("anim").play("atack")
	timer.start()
	yield(timer, "timeout")
	atack = false
	
func _ready():
	timer.set_wait_time(rate_of_fire)
	player = global.player
	projectile_scene = load("res://scenes/actors/poop_projectile.scn")
	set_process(true)
	
