package  
{
	
	import net.flashpunk.graphics.Image;
	import net.flashpunk.FP;
	
	/**
	 * ...
	 * @author Benn
	 */
	public class GreenWorldBoss extends BaseEnemy 
	{
		
		private var BossPhase:int = 0;
		
		private var ProjectileSpawnTimer:Number = 0.9;
		
		private var MaxHP:Number = 25;
		
		private var DamageTimer:Number = 0;
		
		private var BossWaitTimer:Number = 1;
		
		public function GreenWorldBoss(posx:int, posy:int) 
		{
		
			EnemyImage = Image.createRect(100, 100, 0xFFFFFF);
		
			EnemyImage.color = FP.getColorRGB(200, 0, 0);
			
			EnemyImage.centerOrigin();
			
			graphic = EnemyImage;
			
			setHitboxTo(EnemyImage);
			
			type = "enemy";
			
			x = posx;
			y = posy;
			
			moveSpeed = 100;
			
		}
		
		override public function TakeDamage():void 
		{
			
			//dont take damage in the first phase
			if (BossPhase > 0)
			{
			
				DamageTimer = 0.25;
				
				MaxHP -= FP.elapsed;
				
				if (MaxHP <= 0)
				{
					
					var PlayerList:Array = [];
			
					FP.world.getClass(Player, PlayerList);
					
					for each (var P:Player in PlayerList)
					{
						P.PlayerExitGreenWorld = true;
					}
					
					var QuadList:Array = [];
					
					FP.world.getClass(Quad, QuadList);
					
					for each(var Q:Quad in QuadList)
					{
						Q.SetStopping();
					}
					
					FP.world.remove(this);
				}
				
			}
			
		}
		
		override public function update():void 
		{
			
			if (SpawnDelay > 0)
			{
				SpawnDelay -= FP.elapsed;
			}
			else
			{
				
				if (BossPhase == 0)
				{
					
					y += moveSpeed * FP.elapsed;
					
					if (y > 0)
					{
						
						y = 0;
						BossPhase = 1;
						
					}
					
				}
				else if (BossPhase == 1)
				{
					
					BossWaitTimer -= FP.elapsed;
					
					if (BossWaitTimer <= 0)
					{
						BossWaitTimer = 1;
						BossPhase = 2;
					}
					
				}
				else if (BossPhase == 2)
				{
					
					y += (moveSpeed * 8) * FP.elapsed;
					
					if (y > 400)
					{
						y = 400;
						BossPhase = 3;
					}
					
				}
				else if (BossPhase == 3)
				{
					
					y -= moveSpeed * FP.elapsed;
					
					if (y < 0)
					{
						y = 0;
						BossPhase = 1;
					}
					
				}
				
				EnemyImage.angle += 100 * FP.elapsed;
			
				if (DamageTimer > 0)
				{
					DamageTimer -= FP.elapsed;
					
					EnemyImage.color = FP.getColorRGB(255, 255, 255);
					
				}
				else
				{
					
					EnemyImage.color = FP.getColorRGB(200, 0, 0);
					
				}
				
				if (BossPhase > 0)
				{
				
					ProjectileSpawnTimer -= FP.elapsed;
							
					if (ProjectileSpawnTimer < 0)
					{
						var Proj:BaseProjectile = new BaseProjectile(centerX, centerY);
					
						FP.world.add(Proj);
						
						ProjectileSpawnTimer = 0.9;
						
					}
				
				}
				
			}
			
			super.update();
		}
		
	}

}