package  
{
	import net.flashpunk.Entity;
	import net.flashpunk.utils.Draw;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.utils.Data;
	import flash.xml.XMLDocument;
	import flash.xml.XMLNode;

	
	import net.flashpunk.FP;	
	/**
	 * ...
	 * @author AntoineGuerchais
	 */
	public class Tree extends Entity
	{
	
		
		private var gameTime:Number;
		
		private var init:Boolean;
		private var root:Branch;
		public var grow:Boolean;
		
		/*public static function loadTree(src:String):Tree
		{
			var myXML:XML = new XML(); 
			var XML_URL:String = src; 
			var myXMLURL:URLRequest = new URLRequest(XML_URL); 
			var myLoader:URLLoader = new URLLoader(myXMLURL); 
			myLoader.addEventListener("complete", xmlLoaded); 

			var tree:Tree = new Tree();
			//var xml:XMLDocument = new XMLDocument();

			//xml.parseXML();
			//var root:XMLNode;
			//root = xml.childNodes.
			return tree;
		}
		
		function xmlLoaded(event:Event):void 
		{ 
			myXML = XML(myLoader.data); 
			trace("Data loaded."); 
		}*/
		
		public function Tree() 
		{
			init = false;
			gameTime = 0.0;
			grow = true;
		}
		
		override public function update():void
		{
			if (!(FP.world as TreeWorld).paused)
			{
				if (grow)
				{
					gameTime += FP.elapsed;
					//trace("update tree");
					if (!init)
					{	
						//var branch:Branch = new Branch(root);
						
					root = new Branch();
					root.x = FP.width / 2.0;
					root.y = FP.height-50 ;
					root.angle = 0;
						init = true;
					}
					//root.angle += 0.5;
					if (gameTime > 4)
					{
						SoundManager.playBuds();
						root.buds();
						gameTime = 0.0;
					}
				}
			}
		}
		
		override public function render():void
		{
			super.render();
		}
		
		public function stop():void
		{
			root.stop();
			grow = false;
		}
		
	}

}