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

namespace ShootingHero.Components
{
	public class Item : DrawableGameComponent
	{
		Texture2D texture;
		float x, y;

		protected Texture2D Texture { set { texture = value; } }
		public float X { get { return x; } set { x = value; } }
		public float Y { get { return y; } set { y = value; } }

		public Item ( Game game, float x, float y )
			: base ( game )
		{
			this.x = x;
			this.y = y;
		}

		public virtual void DoEffect ( Player player )
		{
			
		}

		public override void Update ( GameTime gameTime )
		{
			y += gameTime.ElapsedGameTime.Milliseconds / 10.0f;

			GameScene gameScene = ( Game.Components [ 0 ] as Transitor ).CurrentScene as GameScene;
			Player player = gameScene.Player;
			if ( MathHelper.Distance ( new Vector2 ( player.X, player.Y ), new Vector2 ( X, Y ) )
				<= texture.Width / 2 + 8 )
			{
				gameScene.ItemManager.Remove ( this );
				player.Score += 10;
				DoEffect ( player );
			}

			base.Update ( gameTime );
		}

		public override void Draw ( GameTime gameTime )
		{
			SpriteBatch spriteBatch = ( Game as ShootingHero ).SpriteBatch;
			spriteBatch.Draw ( texture, new Vector2 ( x - texture.Width / 2, y - texture.Height / 2 ),
				Color.White );

			base.Draw ( gameTime );
		}
	}
}
