package  
{
	import fl.transitions.Fade;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import org.flintparticles.common.actions.Age;
	import org.flintparticles.common.actions.ScaleImage;
	import org.flintparticles.common.counters.Blast;
	import org.flintparticles.common.counters.Steady;
	import org.flintparticles.common.displayObjects.RadialDot;
	import org.flintparticles.common.emitters.Emitter;
	import org.flintparticles.common.initializers.ImageClass;
	import org.flintparticles.common.initializers.Initializer;
	import org.flintparticles.common.initializers.ScaleImageInit;
	import org.flintparticles.common.particles.Particle;
	import org.flintparticles.threeD.initializers.RotateVelocity;
	import org.flintparticles.twoD.actions.DeathZone;
	import org.flintparticles.twoD.actions.Explosion;
	import org.flintparticles.twoD.actions.MouseAntiGravity;
	import org.flintparticles.twoD.actions.Move;
	import org.flintparticles.twoD.actions.RotateToDirection;
	import org.flintparticles.twoD.emitters.Emitter2D;
	import org.flintparticles.twoD.initializers.Position;
	import org.flintparticles.twoD.initializers.Velocity;
	import org.flintparticles.twoD.renderers.DisplayObjectRenderer;
	import org.flintparticles.twoD.zones.DiscSectorZone;
	import org.flintparticles.twoD.zones.DiscZone;
	import org.flintparticles.twoD.zones.LineZone;
	import org.flintparticles.twoD.zones.PointZone;
	import org.flintparticles.twoD.zones.RectangleZone;
	
	public class Main extends MovieClip {
		
		private var countDown:int = 15
		private var imageList:Array = [Image1, Image2, Image3,  Image4]
		private var myRenderer:DisplayObjectRenderer = new DisplayObjectRenderer();
		private var myEmitter:Emitter2D = new Emitter2D()
		
		public function Main() {
			addEventListener(Event.ENTER_FRAME, enterFrame)
		
			
			myEmitter.counter = new Steady( 10 );
			myEmitter.addInitializer(new ImageClass(bubble_mc));
			myEmitter.addInitializer(new Position(new LineZone(new Point(0,700),new Point(830,700))))
			myEmitter.addInitializer( new Velocity( new PointZone( new Point( 0, -65 ) ) ) );
			myEmitter.addInitializer( new ScaleImageInit( 0.75, 5 ) );

			myEmitter.addAction( new Move() );
			myEmitter.addAction( new DeathZone( new RectangleZone(-40,-40,850,750), true ) );
			myEmitter.addAction(new MouseAntiGravity(10,myRenderer,1))
			myEmitter.start();

			
			myRenderer.addEmitter( myEmitter );
			addChild( myRenderer );

		}
		
		private function enterFrame(e:Event):void 
		{
			countDown--
			if (countDown <= 0) {
				
				var myNewBubble:MovieClip = new MovieClip()
				myNewBubble.addChild(new MaskMC())
				var myImageInBubble:MovieClip = new imageList[Math.floor(Math.random() * imageList.length)]()
				myNewBubble.addChild(myImageInBubble)
				myImageInBubble.mask = myNewBubble.getChildAt(0)

				myNewBubble.y = 800
				myNewBubble.x = Math.random() * stage.width
			
				myNewBubble.addEventListener(Event.ENTER_FRAME, bubbleFrameEnter)
				addChild(myNewBubble)
				
				
				countDown = 30
				
				
			}
		}	
		
		private function bubbleFrameEnter(e:Event):void 
		{
			e.target.y -= 7
			if (e.target.y < 0) {
				
				 var newE:Emitter2D = new Emitter2D();
				
				myRenderer.addEmitter(newE);
				newE.counter = new Blast(20);
				newE.addInitializer(new ImageClass(bubble_mc2));
				newE.addInitializer(new Position(new DiscZone(new Point(e.target.x + 75, e.target.y + 75),50,50)));
				newE.addAction(new Explosion(5, e.target.x + 75 , e.target.y + 75, 2000,20, 1));
				newE.addAction(new Move());
				newE.addAction(new Move());
				newE.addAction(new DeathZone(new RectangleZone(-30, -30, 820, 620), true));
				newE.start();            
	
				e.target.parent.removeChild(e.target)
				e.target.removeEventListener(Event.ENTER_FRAME, bubbleFrameEnter)

			}
		}
		
	}

}