package enemies 
{
	import engine.MathExt;
	import flash.geom.Point;
	/**
	 * ...
	 * @author Fiodar Paulavets
	 */
	public class EnemyHelicopter extends Enemy 
	{
		private var time: Number;
		private var shootTime: Number, shootQueue: Number;
		private var queue: int;
		
		public function EnemyHelicopter() 
		{
			super(HelicopterClip, 115);
			
			x = Game.screenWidth + _clip.width;
			y = 50 + (Game.screenHeight - 230) * Math.random();
			
			_velocity.x = 60;
			_velocity.y = 20;
			
			life = 8;
			radius = 32;
			
			target = new Point(x - 200 + Math.random() * 150, y);
			
			time = 20;
			
			shootTime = 2;
			queue = 0;
			shootQueue = 0;
		}
		
		override public function Update(dt:Number):void 
		{
			// улететь после 30 секунд
			time -= dt;
			if (time <= 0)
			{
				target.x = Game.screenWidth * 2;
				target.y = y;
				_velocity.x = 60;
				time = 100;
			}
			
			// цель
			if (MathExt.Distance(x, y, target.x, target.y) <= 1)
			{
				target.x = Game.screenWidth - 200 + Math.random() * 150;
				target.y = Math.max(50, Math.min(Game.screenHeight - 150, y + (1 - Math.random() * 2) * 100));
				_velocity.x = 20;
			}
			
			// стрельба
			shootTime -= dt;
			if (shootTime <= 0)
			{
				queue = 5;
				shootTime = 2.5;
				shootQueue = 0;
			}			
			if (queue > 0)
			{
				shootQueue -= dt;
				if (shootQueue <= 0)
				{
					World.world.bulletsList.add(new Bullet(x - 35, y + 26, false, -1, 0));
					shootQueue = 0.075;
					queue--;
				}
			}
			
			super.Update(dt);
		}
		
	}

}