package  
{
	import flash.display.Sprite;
	import flash.events.Event;
	import interfaces.IGameObject;
	
	/**
	 * ...
	 * @author Fiodar Paulavets
	 */
	public class Explosion extends Sprite implements IGameObject 
	{
		private var _particles: Vector.<ParticleClip> = new Vector.<ParticleClip>;
		private var _dead: Boolean = false;
		
		public function Explosion(x: Number, y: Number) 
		{
			this.x = x;
			this.y = y;
			for (var i: uint = 0; i < 20; i++)
			{
				_particles[i] = new ParticleClip();
				_particles[i].rotation = Math.random() * 360;
				_particles[i].scaleX = _particles[i].scaleY = 0.3 + Math.random() * 0.7;
				_particles[i].x = (Math.random() * 2 - 1) * 10;
				_particles[i].y = (Math.random() * 2 - 1) * 10;
				addChild(_particles[i]);
				_particles[i].play();
				_particles[i].addEventListener(Event.ENTER_FRAME, particles_enterFrame);
			}
		}
		
		private function particles_enterFrame(e:Event):void 
		{
			if (ParticleClip(e.target).currentFrame == ParticleClip(e.target).totalFrames)
			{
				ParticleClip(e.target).stop();
				_dead = true;
			}
		}
		
		/* INTERFACE interfaces.IGameObject */
		
		public function Update(dt:Number):void 
		{
			if (_dead)
				World.world.particlesList.remove(this);
		}
		
	}

}