extends Area2D

export var enemy_path: String = 'res://Enemies/ENEMY.tscn'
export var relative_x_tiles: int
export var relative_y_tiles: int


func _on_spawn_trap_area_entered(area: Area2D) -> void:
    if area.get_parent().name == 'Player':
        set_deferred('monitoring', false)

        var enemy: KinematicBody2D = load(enemy_path).instance()
        enemy.position.x = position.x + (relative_x_tiles * 16 + 8)
        enemy.position.y = position.y + (relative_y_tiles * 16 + 8)

        var enemies: YSort = get_tree().get_current_scene().get_node('YSort/Enemies')
        enemies.call_deferred('add_child', enemy)
        call_deferred('queue_free')
    return
