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

namespace ShootingHero.Utilities
{
	public class EffectAnimation
	{
		Texture2D texture;
		int index;
		Timer timer = new Timer ( 100 );
		bool isEnded = false;
		float x, y;
		int maximumCount;

		public Texture2D Texture { get { return texture; } set { texture = value; } }
		public bool IsEnded { get { return isEnded; } }

		public EffectAnimation ( Texture2D texture, float x, float y, int maximumCount )
		{
			this.texture = texture;
			this.x = x;
			this.y = y;
			this.maximumCount = maximumCount;
		}

		public void Update ( GameTime gameTime )
		{
			timer.Update ( gameTime );
			if ( timer.CheckTimer && !isEnded )
			{
				index++;
				if ( index >= maximumCount )
				{
					index--;
					isEnded = true;
				}
				timer.Reset ();
			}
		}

		public void DrawAnimation ( SpriteBatch spriteBatch )
		{
			spriteBatch.Draw ( texture, new Vector2 ( x, y ),
				new Rectangle ( index * texture.Width / maximumCount, 0,
					texture.Width / maximumCount, texture.Height ),
				Color.White, 0, new Vector2 ( texture.Width / ( maximumCount * 2 ), texture.Height / 2 ),
				1.0f, SpriteEffects.None, 0 );
		}
	}
}
