using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using ShootingHero.Components.Bullets.BossBullet;
using ShootingHero.Components.Manager;
using ShootingHero.Scene;

namespace ShootingHero.Components.Monsters.Bosses
{
	public class HugeSpider : Boss
	{
		static Texture2D texture;

		float shootAngle;
		Timer timer;

		public HugeSpider ( Game game, float timeUnit )
			: base ( game, timeUnit, 800 )
		{
			if ( texture == null || texture.IsDisposed )
				texture = Game.Content.Load<Texture2D> ( "Boss/spider" );
			Texture = texture;
			TadaPosition = 120;
			Width = texture.Height / 2 - 40;
			Timer.Delay = 100;
			timer = new Timer ( 800 );
		}

		protected override void ShootBullet ( BulletManager bulletManager )
		{
			ShootBulletEx ( bulletManager, false );
		}

		void ShootBulletEx ( BulletManager bulletManager, bool guidedBulletMode )
		{
			if ( !guidedBulletMode )
			{
				for ( int i = 0; i < 360; i += 30 )
					bulletManager.Add ( new SpiderBullet ( Game, X, Y, shootAngle + Microsoft.Xna.Framework.MathHelper.ToRadians ( i ) ) );
				/*
				bulletManager.Add ( new SpiderBullet ( Game, X, Y, shootAngle + 3.141592f / 2 ) );
				bulletManager.Add ( new SpiderBullet ( Game, X, Y, shootAngle + 3.141592f ) );
				bulletManager.Add ( new SpiderBullet ( Game, X, Y, shootAngle + 3.141592f + 3.141592f / 2 ) );
				 * */
			}
			else
			{
				Player player = ( ( Game.Components [ 0 ] as Transitor ).CurrentScene as GameScene ).Player;
				float angle = ( float ) Math.Atan2 ( player.Y - Y, player.X - X ) + 3.141592f / 2;
				bulletManager.Add ( new SpiderBullet ( Game, X, Y, angle ) );
			}
		}

		protected override void MoveLogic ( GameTime gameTime )
		{

		}

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

			timer.Update ( gameTime );
			if ( timer.CheckTimer )
			{
				BulletManager bulletManager = ( ( Game.Components [ 0 ] as Transitor ).CurrentScene as GameScene ).BulletManager;
				ShootBulletEx ( bulletManager, true );
				timer.Reset ();
			}

			base.Update ( gameTime );
		}
	}
}
