﻿using FurryRun.Core;
using Microsoft.Xna.Framework;

namespace FurryRun.Effects
{
    public class FadeImageEffect : GameImageEffect
    {
        public float FadeSpeed { get; set; }
        public bool Increase { get; set; }

        public FadeImageEffect()
        {
            FadeSpeed = 0.5f;
            Increase = false;
        }

        public override void UnloadContent()
        {
        }

        public override void Update(GameTime gameTime)
        {
            if (IsActive)
            {
                if (!Increase)
                    Image.Alpha -= FadeSpeed*(float) gameTime.ElapsedGameTime.TotalMilliseconds/1000;
                else
                    Image.Alpha += FadeSpeed*(float) gameTime.ElapsedGameTime.TotalMilliseconds/1000;

                if (Image.Alpha < 0.0f)
                {
                    Increase = true;
                    Image.Alpha = 0.0f;
                }
                else if (Image.Alpha > 1.0f)
                {
                    Increase = false;
                    Image.Alpha = 1.0f;
                }
            }
            else
            {
                Increase = false;
                Image.Alpha = 1.0f;
            }
        }
    }
}