package enemies 
{
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	/**
	 * ...
	 * @author beisik
	 */
	public class Creator 
	{
		private static var wave: Vector.<Creator>;
		
		private var timer: Timer;
		private var enemyType: Class;
		
		public function Creator(time: Number, type: Class) 
		{
			timer = new Timer(time * 1000, 1);
			enemyType = type;
			timer.addEventListener(TimerEvent.TIMER, onTime);
		}
		
		private function onTime(e: TimerEvent): void
		{
			//
			wave.splice(wave.indexOf(this, 0), 1);
			World.world.enemiesList.add(new enemyType());
		}
		
		/**
		 * time - в секундах
		 */
		public static function add(time: Number, type: Class): void
		{
			if (!wave)
				wave = new Vector.<Creator>();
			wave.push(new Creator(time, type));
		}
		
		public static function startWave(): void
		{
			if (!wave)
				wave = new Vector.<Creator>();
			for each (var creator: Creator in wave)
				creator.timer.start();
		}
		
		public static function pauseWave(): void
		{
			if (!wave)
				wave = new Vector.<Creator>();
			for each (var creator: Creator in wave)
				creator.timer.stop();
		}
		
		public static function destroyWave(): void
		{
			wave = null;
		}
		
		public static function getCount(): uint
		{
			if (!wave)
				wave = new Vector.<Creator>();
			return wave.length;
		}
		
	}

}