package  
{
	import net.flashpunk.*;	
	import net.flashpunk.graphics.*;	
	import net.flashpunk.masks.*;	
	import net.flashpunk.utils.*;	
	import flash.display.*;
	import flash.display.BitmapData;
	import flash.geom.Point;
	import net.flashpunk.Entity;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.utils.Input;
	import net.flashpunk.utils.Key;
	import net.flashpunk.FP;
	import net.flashpunk.Sfx;
	import net.flashpunk.graphics.Spritemap;
	
	public class haloProjectile extends Entity
	{
		internal var hit:Boolean = false;
		internal var initDirection:String;
		
		/*halo graphic*/
		[Embed(source = '../assets/gfx/fish-halo-sprite.png')] 
		private const HALO:Class;
			
		public var haloSprite:Spritemap = new Spritemap(HALO, 48, 48);
			
		public function haloProjectile() 
		{
			//set position & direction
			x = GameWorld.fish.x;
			y = GameWorld.fish.y;
			initDirection = GameWorld.fish.direction;
			
			haloSprite.add("shootR", [1], 20, false);
			haloSprite.add("shootL", [0], 20, false);			
			graphic = haloSprite;
			setHitbox(48, 15, 0, 0);
		}
		
		override public function update():void{
			updateMovement(); 
			super.update();
		}
		
		private function updateMovement():void 
		{		
			//check collision with level
			if (initDirection == "faceR")
			{
				haloSprite.play("shootR");
				//if not colliding with level move halo forward
				if((!collide("level", x, y) && y < 480) || (!collide("level", x, y) && y == 480))
				{
					x += 2;
				}
				else
				{
					world.remove(this);
					GameWorld.haloNum--;
				}
			}
			else
			{
				haloSprite.play("shootL");
				if((!collide("level", x, y) && y < 480) || (!collide("level", x, y) && y == 480))
				{
					x -= 2;
				}
				else
				{
					world.remove(this);
					GameWorld.haloNum--;
				}
			}
			//check collision with bunny			
			if (GameWorld.player1Type == "B" || GameWorld.player2Type == "B")
			{
				if (GameWorld.fish.direction == "faceR")
				{
					//check collision to right
					if (collideRect(x, y, GameWorld.bunny.x, GameWorld.bunny.y, 48, 48))
					{
						GameWorld.bIsHit = true;
						if (GameWorld.player1Type == "B")
						{
							GameWorld.hit1 = true;
						}
						if (GameWorld.player2Type == "B")
						{
							GameWorld.hit2 = true;
						}
						world.remove(this);
						
					}
				}
				else
				{
					//check collision to left
					if (collideRect(x, y, GameWorld.bunny.x, GameWorld.bunny.y, 48, 48))
					{
						GameWorld.bIsHit = true;
						if (GameWorld.player1Type == "B")
						{
							GameWorld.hit1 = true;
						}
						if (GameWorld.player2Type == "B")
						{
							GameWorld.hit2 = true;
						}
						world.remove(this);
					}
				}
			}//end if collide with bunny
			
			//check collision with robot
			if (GameWorld.player1Type == "R" || GameWorld.player2Type == "R")
			{
				if (GameWorld.fish.direction == "faceR")
				{
					//check collision to right
					if (collideRect(x, y, GameWorld.robot.x, GameWorld.robot.y, 48, 48))
					{
						GameWorld.rIsHit = true;
						if (GameWorld.player1Type == "R")
						{
							GameWorld.hit1 = true;
						}
						if (GameWorld.player2Type == "R")
						{
							GameWorld.hit2 = true;
						}
						world.remove(this);
						
					}
				}
				else
				{
					//check collision to left
					if(collideRect(x, y, GameWorld.robot.x, GameWorld.robot.y, 48, 48))
					{
						GameWorld.rIsHit = true;
						if (GameWorld.player1Type == "R")
						{
							GameWorld.hit1 = true;
						}
						if (GameWorld.player2Type == "R")
						{
							GameWorld.hit2 = true;
						}
						world.remove(this);
						
					}
				}
			}//end if robot to collide with
		}
	}

}