extends Node2D

export var moving_area = Vector2()
export var _name = ""
export var respawn_time = 0
var id = 0
var type = "mob"
var dir = 1
var health = 10

func _process(delta):
	position.x += 140 * delta * dir
	if position.x < moving_area.x or position.x > moving_area.y:
		dir *= -1
		scale.x *= -1
		
func apply_damage(s):
	health -= s
	if health <= 0:
		die()
		return true
	return false
	
func die():
	if respawn_time == 0: 
		queue_free()
	else:
		var coll = $interract/CollisionShape2D
		var timer = $spawn_time
		var anim = $anim
		coll.disabled = true
		$Sprite.modulate = Color("00ffffff")
		timer.wait_time = respawn_time
		timer.start()
		yield(timer, "timeout")
		anim.play("appear")
		yield(anim,"animation_finished")
		coll.disabled = false
