using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace GraveyardGraph
{
	public class AnimatedTexture
	{
		private float spf;
		private Texture2D[] textures;

		private float animationDuration
		{
			get { return textures.Length * spf; }
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="T:GraveyardGraph.AnimatedTexture"/> class.
		/// </summary>
		/// <param name="spf">Seconds per frame of this animation.</param>
		/// <param name="textures">An array of all the frames of this animation.</param>
		public AnimatedTexture(float spf, params Texture2D[] textures)
		{
			this.spf = spf;
			this.textures = textures;
		}

		public Texture2D GetFrame(GameTime time)
		{
			float curTimeInSec = (float)time.TotalGameTime.TotalSeconds;
			float animTime = curTimeInSec % animationDuration;
			float animFrame = animTime / spf;
			int frame = (int)animFrame;
			if (frame >= textures.Length)
			{
				frame = textures.Length - 1;
			}
			return textures[frame];
		}
	}
}
