using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using ShootingHero.Scene;
using ShootingHero.Components.Manager;
using Microsoft.Xna.Framework.Audio;

namespace ShootingHero.Components.Bullets
{
	public class HeroBullet : Bullet
	{
		int width;
		int power;
		bool isNondestroyBullet = false;

		List<Monster> touchedMonsterList = new List<Monster> ();

		public int Power { get { return power; } protected set { power = value; } }
		public int Width { get { return width; } set { width = value; } }
		public bool IsNondestroyBullet { get { return isNondestroyBullet; } set { isNondestroyBullet = value; } }

		public HeroBullet ( Game game, float x, float y, float angle, float speed ) :
			base ( game, x, y, angle, speed )
		{
			this.power = 1;
		}

		public override void Update ( GameTime gameTime )
		{
			GameScene gameScene = ( Game.Components [ 0 ] as Transitor ).CurrentScene as GameScene;
			MonsterManager monsterManager = gameScene.MonsterManager;

			foreach ( Monster monster in monsterManager.Container )
			{
				if ( !monster.CheckTimeUnit )
				{
					if ( MathHelper.Distance ( new Vector2 ( monster.X, monster.Y ), new Vector2 ( X, Y ) )
					<= Width / 2 + monster.Width )
					{
						if ( !isNondestroyBullet )
							gameScene.BulletManager.Remove ( this );
						if ( touchedMonsterList.IndexOf ( monster ) < 0 )
						{
							gameScene.Player.ChangePoint++;
							gameScene.Player.Score += 10;
							monster.HealthPoint -= power;
							gameScene.EffectManager.Add ( X, Y, true );
							touchedMonsterList.Add ( monster );
							PlaySound ();
						}
					}
				}
			}

			base.Update ( gameTime );
		}
	}
}
