package  
{
	import flash.display.Sprite;
	import flash.filters.BlurFilter;
	import flash.filters.BitmapFilterQuality;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.ui.Mouse;
	import org.flintparticles.common.actions.Age;
	import org.flintparticles.common.actions.Fade;
	import org.flintparticles.common.counters.Steady;
	import org.flintparticles.common.displayObjects.Line;
	import org.flintparticles.common.energyEasing.Cubic;
	import org.flintparticles.common.initializers.ColorInit;
	import org.flintparticles.common.initializers.Lifetime;
	import org.flintparticles.common.initializers.SharedImages;
	import org.flintparticles.twoD.actions.Move;
	import org.flintparticles.twoD.actions.RotateToDirection;
	import org.flintparticles.twoD.activities.FollowMouse;
	import org.flintparticles.twoD.emitters.Emitter2D;
	import org.flintparticles.twoD.initializers.Position;
	import org.flintparticles.twoD.initializers.Velocity;
	import org.flintparticles.twoD.renderers.BitmapRenderer;
	import org.flintparticles.twoD.zones.DiscSectorZone;
	import org.flintparticles.twoD.zones.PointZone;
	
	
	public class AnimatedCursor extends Sprite
	{
		private var _isRunning:Boolean;
		
		private var renderer:BitmapRenderer;
		private var emitter:Emitter2D;
		private var bombImage:Sprite;
		private var blurFilter:BlurFilter;
		
		public function AnimatedCursor() 
		{
			bombImage = new Bomb();
			addChild(bombImage);
			bombImage.visible = false;
			
			_isRunning = false;
			
			blurFilter = new BlurFilter(6, 6, BitmapFilterQuality.HIGH);			
			renderer = new BitmapRenderer(new Rectangle(0, 0, 600, 400));
			renderer.addFilter(blurFilter);
			addChild(renderer);
			
			emitter = new Emitter2D();
			renderer.addEmitter(emitter);
			emitter.counter = new Steady(30);
			
			var imageArray:Array = new Array();
			imageArray.push(new Line(1));
			imageArray.push(new Line(2));
			imageArray.push(new Line(3));
			var imageWeights:Array = [4, 6, 3];			
			
			emitter.addInitializer( new SharedImages(imageArray, imageWeights));
			emitter.addInitializer( new ColorInit( 0xFFFFCC00, 0xFFF9F7BF ) );
			emitter.addInitializer( new Velocity( new DiscSectorZone( new Point( 0, 0 ), 90, 30, -1.5, 0.5 ) ) );
			emitter.addInitializer( new Lifetime( 0.15, 0.5 ) );
			emitter.addInitializer( new Position(new PointZone(new Point(8, -6))));
			
			emitter.addAction( new Age(Cubic.easeIn) );
			emitter.addAction( new Move() );
			emitter.addAction( new Fade() );
			emitter.addAction( new RotateToDirection() );
			emitter.addActivity( new FollowMouse( renderer ) );
			
		}
		
		public function updateCursorPosition(x:int, y:int):void
		{
			bombImage.x = x;
			bombImage.y = y;
		}
		
		public function start():void
		{
			Mouse.hide();
			bombImage.visible = true;
			emitter.start();
			_isRunning = true;
		}
		
		public function stop():void
		{
			Mouse.show();
			bombImage.visible = false;
			emitter.stop();
			renderer.bitmapData.fillRect(renderer.bitmapData.rect, 0);
			_isRunning = false;
		}
		
		public function get isRunning():Boolean
		{
			return _isRunning;
		}
	}
}