package Game.Objects
{
	import Engine.GameSprite;
	import flash.display.SimpleButton;
	import flash.geom.Point;
	import flash.media.Sound;
	import Game.Effects.Explosion;
	import Game.LibGraphics;
	import Game.LibSounds;
	import Game.Objects.Bullets.FireBullet;
	import Game.Objects.Bullets.SimpleBullet;
	import Game.Objects.Bullets.UFOBullet;
	
	/**
	 * ...
	 * @author KEFIR
	 */
	public class FlyerEnemy extends GameSprite
	{
		private var _angle:Number;
		private var _health:int = 20;
		
		public var initY:int;
		
		private var _burstInterval:int = 0;
		private var _burstCount:int = 0;
		private var _shotInterval:int = 0;
		
		override public function Move():void
		{
			if (x > 400) {
				x = x - 2;
			}else {
				y = initY + Math.sin(_angle) * 100;
				_angle += 0.03;
				
				if (_burstInterval == 0) {
					if (_shotInterval == 0) {
						var b1:UFOBullet = new UFOBullet();
						var b2:UFOBullet = new UFOBullet();
						
						b1.y = y - 42;
						b2.y = y + 42;
						
						b1.x = x;
						b2.x = x;
						
						b1.vector = new Point( -1, 0);
						b2.vector = new Point( -1, 0)
						
						Group.AddSprite(b1);
						Group.AddSprite(b2);
						
						var snd:Sound = new LibSounds.Shot2();
						snd.play();
						
						_shotInterval = 3;
						_burstCount++;
						
						if (_burstCount == 3) {
							_burstInterval = 30;
							_burstCount = 0;
							_shotInterval = 0;
						}
					}else {
						_shotInterval--;
					}
				}else {
					_burstInterval--;
				}
			}
		}
		
		override public function Collision(Intersects:GameSprite):void
		{
			if (Intersects is SimpleBullet) {
				Intersects.Delete = true;
				
				_health--;
				
				
			}
			
			if (Intersects is FireBullet) {
				Intersects.Delete = true;
				
				_health -= 5;
			}
			
			if (_health <= 0) {
				Delete = true;
				Group.AddSprite(new Explosion(x, y));
			}
		}
		
		public function FlyerEnemy()
		{
			super(new LibGraphics.FlyerEnemy(), new Point(45, 45));
			
			_angle = 0;
			CollisionEnabled = true;
		}
		
	}

}