package Game{
	import flash.display.*;
	import fl.transitions.Tween;
	import fl.transitions.easing.*;
	import fl.transitions.TweenEvent;
	
	public class LifesHUD extends MovieClip{
		var LifesMc:Array = new Array();
		var Tweens:Array = new Array();
		
		function LifesHUD(){
		}
		
		public function SetLifes(num:Number):void{
			for(var i:Number = 0; i < LifesMc.length; i++){
				removeChild(LifesMc[i]);
			}
			
			LifesMc = new Array();
			
			for(i = 0; i < num; i++){
				LifesMc[i] = new LifeHUDSprite();
				LifesMc[i].x = i * 24;
				LifesMc[i].y = 0;
				addChild(LifesMc[i]);
			}
		}
		
		public function IncLifes():void{
			var i:Number = LifesMc.length;
			LifesMc[i] = new LifeHUDSprite();
			LifesMc[i].x = i * 24;
			LifesMc[i].y = 0;
			addChild(LifesMc[i]);
		}
		
		function onLifeDisapear(e:TweenEvent):void{
			removeChild(LifesMc.pop());
			
			var ti:Number = Tweens.indexOf(e.target);
			Tweens[ti] = Tweens[Tweens.length - 1];
			Tweens.pop();
		}
		
		public function DecLifes():void{
			var life:MovieClip = LifesMc[LifesMc.length-1];
			var t:Tween = new Tween(life, 'x', Strong.easeIn, life.x, -20, 1.5, true);
			t.addEventListener(TweenEvent.MOTION_FINISH, onLifeDisapear);
			
			Tweens[Tweens.length] = t;
		}
	}
}