package Game.Objects
{
	import Engine.GameSprite;
	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.RocketBullet;
	import Game.Objects.Bullets.SimpleBullet;
	import Game.Objects.Bullets.UFOBullet;
	import Game.SceneGame;
	
	/**
	 * ...
	 * @author KEFIR
	 */
	public class Boss extends GameSprite
	{
		private var _health:int = 350;
		private var _dieing:Boolean = false;
		private var _finaly_dead:Boolean = false;
		private var _explInterval:int = 0;
		private var _explCnt:int = 0;
		
		private var _currentGun:int = 0;
		private var _bulletInterval:int = 0;
		private var _rocketsInterval:int = 0;
		
		private var _fireSnd:Sound = new LibSounds.Shot2() as Sound;
		
		override public function Move():void
		{
			if(!_dieing){
				if (x > 500) {
					x = x - 3;
				}else {
					if (_bulletInterval == 0) {
						var b1:UFOBullet = new UFOBullet();
						var b2:UFOBullet = new UFOBullet();
						var b3:UFOBullet = new UFOBullet();
						
						b1.vector = new Point( -1, 0);
						b2.vector = new Point( -1, 0);
						b3.vector = new Point( -1, 0);
						
						b1.y = y - 105;
						b2.y = y;
						b3.y = y + 105;
						
						b1.x = x;
						b2.x = x;
						b3.x = x;
						
						Group.AddSprite(b1);
						Group.AddSprite(b2);
						Group.AddSprite(b3);
						
						_fireSnd.play();
						
						_bulletInterval = 15;
					}else {
						_bulletInterval--;
					}
					
					if (_rocketsInterval == 0) {
						var r1:RocketBullet = new RocketBullet();
						var r2:RocketBullet = new RocketBullet();
						
						r1.x = x;
						r2.x = x;
						
						r1.y = y - 50;
						r2.y = y + 50;
						
						Group.AddSprite(r1);
						Group.AddSprite(r2);
						
						_rocketsInterval = 150;
					}else {
						_rocketsInterval--;
					}
				}
				
				if (y < (Group as SceneGame).Player.y) {
					y += 1;
				}
				
				if (y > (Group as SceneGame).Player.y) {
					y -= 1;
				}
			}else {
				if (_finaly_dead) {
					y = y + 3;
					
					if (y >= 600) {
						(Group as SceneGame).Win();
						Delete = true;
					}
				}else {
					if (_explInterval == 0) {
						Group.AddSprite(new Explosion(x - width / 2 + Math.random() * width, y - height / 2 + Math.random() * height));
						_explInterval = 5;
						_explCnt++;
						if (_explCnt == 20) {
							_finaly_dead = true;
						}
					}else {
						_explInterval--;
					}
				}
			}
			
		}
		
		override public function Collision(Intersects:GameSprite):void
		{
			if (_dieing) {
				
			}else {
				if (Intersects is SimpleBullet) {
					Intersects.Delete = true;
					_health -= 3;
				}
				
				if (Intersects is FireBullet) {
					Intersects.Delete = true;
					_health -= 5;
				}
				
				if (_health <= 0) {
					_dieing = true;
				}
			}
		}
		
		public function Boss()
		{
			super(new LibGraphics.Boss(), new Point(100, 123));
			CollisionEnabled = true;
		}
		
	}

}