package  
{
    import flash.display.MovieClip;
    import flash.events.Event;
	import flash.geom.Point
	public class spikebullet extends MovieClip
	{
		var directionRight:Boolean = true;
		var stepspeed:Number = 0;
		public function spikebullet(goRight:Boolean, posX:Number, posY:Number, speed:int) 
		{
				x = posX;
			y = posY;
			directionRight = goRight;
			stepspeed = speed;
            addEventListener(Event.ENTER_FRAME, loop);
			if(directionRight)
			{
				scaleX = 1;
			}else
			{
				scaleX = -1;
			}
		}
		public function loop(e:Event):void 
		{
			if(!MovieClip(root).dead && !MovieClip(root).win)
			{
				if(directionRight)
				{
					scaleX = 1;
					x = x + stepspeed;
				}else
				{
					scaleX = -1;
					x = x - stepspeed;
				}
			}
			if(MovieClip(root).map.hitTestPoint(x + 16 + MovieClip(root).spike.x, y + 8, true) && directionRight)
       		{
				destroy();
			}
			if(MovieClip(root).map.hitTestPoint(x - 16 + MovieClip(root).spike.x, y + 8, true) && !directionRight)
       		{
				destroy();
			}
			if(x + MovieClip(root).spike.x > stage.stageWidth || x + MovieClip(root).spike.x < 0)
			{
				destroy();
			}
	    }
		public function destroy():void 
		{
			this.parent.removeChild(this);
			removeEventListener(Event.ENTER_FRAME, loop);
		}
	}
	
}
