using Framework.Entities;
using Framework.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Project.Effects
{
    public class SongNoteEffect : CoreBehaviour
    {
        public float time = 0.5f;
        public float heightMax = 2f;
        private new SpriteRenderer renderer;
        private UnityTimer lifeTimer;
        private Vector3 startLocalPosition;

        // Use this for initialization
        protected override void InnerAwake()
        {
            this.renderer = GetComponent<SpriteRenderer>();
            this.lifeTimer = new UnityTimer(this.time, false);
            
        }

        protected override void InnerStart()
        {
            this.startLocalPosition = this.transform.localPosition;
        }

        // Update is called once per frame
        protected override void InnerUpdate()
        {
            this.lifeTimer.Advance();
            float phase = this.lifeTimer.GetCurrent() / this.lifeTimer.GetEnd();
            this.transform.localPosition = this.startLocalPosition + (Vector3.up * phase * this.heightMax);
            this.renderer.color = new Color(this.renderer.color.r, this.renderer.color.g, this.renderer.color.b, 1 - phase);
            if (this.lifeTimer.IsComplete())
            {
                Destroy(this.gameObject);
            }
        }
    }
}
