using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

namespace AnimationPath
{
   class AnimationPath
   {
      Vector3 startPos = Vector3.Zero;
      Vector3 endPos = Vector3.Zero;
      
      public AnimationPath()
      {
      
      }
      
      
      public AnimationPath(Vector3 start, Vector3 end)
      {
         startPos = start;
         endPos = end;
      }
      
      
      public Vector3 Start
      {
         get { return startPos; }
         set { startPos = value; }
      }
      
      
      public Vector3 End
      {
         get { return endPos; }
         set { endPos = value; }
      }
   }
   
   
   class AnimationRoute
   {
      List<AnimationPath> animationPath = new List<AnimationPath>();
      int currentPath = 1;
      float elapsedAnimationTime = 0.0f;
      
      public AnimationRoute()
      {
      
      }
      
      
      public void AddPath(Vector3 start, Vector3 end)
      {
         animationPath.Add(new AnimationPath(start, end));
      }
      
      
      public Vector3 GetPosition(int time, float speed)
      {
         elapsedAnimationTime += time * speed;

         Vector3 pos = Vector3.Lerp(animationPath[currentPath - 1].Start,
                                    animationPath[currentPath - 1].End,
                                    elapsedAnimationTime);

         if(elapsedAnimationTime >= 1.0f)
         {
            elapsedAnimationTime = 0;
            currentPath++;

            if(currentPath > animationPath.Count)
               currentPath = 1;
         }
         
         return pos;
      }
      
      
      public int Count
      {
         get { return animationPath.Count; }
      }
   }
}
