extends Area2D

export (bool) var ALIVE 

signal emitting
signal endemitting
signal enemydestroyed
var isemitting = false

var timer

func _input(event):
   # Mouse in viewport coordinates
	if event is InputEventMouseButton:
		if event.button_index == 1:
			if not isemitting and ALIVE:
				print("Mouse Click/Unclick at: ", event.position)
				position = event.position
				timer.start()
				isemitting = true
				$ASP2D_laser.play()
				emit_signal("emitting")
				show()
		

func _draw():
    #your draw commands here
    pass

func _ready():
	set_process_input(true)
	timer = get_node("Timer")
	timer.set_wait_time(.5)
	timer.connect("timeout", self, "_on_Timer_timeout")
	self.hide()

func _on_Timer_timeout():
	emit_signal("endemitting")
	self.hide()
	position.x = -25
	isemitting = false
	

#func _process(delta):
#	# Called every frame. Delta is time since last frame.
#	# Update game logic here.
#	pass


func _on_Emitter_body_entered(body):
	print("Emitter hit")
	if body.get_name().matchn("*enemy*"):
		emit_signal("enemydestroyed")
		body.DIE = 1
		#body.queue_free()
	
