using UnityEngine;
using System.Collections;

public class MeleeAttackRender : Render
{
    private Transform mover;
    private Vector2 startPoint;
    private Vector2 endPoint;

    public MeleeAttackRender(Transform toMove, Vector2 start, Vector2 end, float time = 0.25f, string smashPrefabName = "SmashRed")
    {
        renderDuration = time;
        nextRenderDelay = renderDuration * 0.6f;
        mover = toMove;
        startPoint = start;
        endPoint = end;

        AddTrigger(new RenderTrigger(() => GameObject.Instantiate(Resources.Load(smashPrefabName), startPoint + (endPoint - startPoint) * 0.8f, Quaternion.identity), 0.5f));

        mover.position = startPoint;
    }

    override public void RenderProgress(float progressFactor)
    {
        if (mover == null)
            return;

        float yoyo = 0.5f - Mathf.Abs(0.5f - progressFactor);
        mover.position = startPoint + (endPoint - startPoint) * yoyo;
    }
}
