package  
{
	import net.flashpunk.Entity;	
	import net.flashpunk.FP;
	import net.flashpunk.graphics.Graphiclist;
	import net.flashpunk.utils.Draw;
	import net.flashpunk.graphics.Image;
	/**
	 * ...
	 * @author AntoineGuerchais
	 */
	public class Season extends Entity
	{
		[Embed(source = '../assets/graphics/BG/season_spring.png')] 
	    private const SeasonSpring:Class;
		[Embed(source = '../assets/graphics/BG/season_summer.png')] 
		private const SeasonSummer:Class;
		[Embed(source = '../assets/graphics/BG/season_automn.png')] 
		private const SeasonAutomn:Class;
		[Embed(source = '../assets/graphics/BG/season_winter.png')] 
		private const SeasonWinter:Class;

		
		
		public var image:Image;
		private var year:Year;
		public var numSeason:int;
		public var season2:Season2;
		public var init:Boolean;
		
		public function Season(num:int,year:Year) 
		{
			switch(num)
			{
				case 0 : 
					image = new Image(SeasonSpring);
					break;
				case 1 : 
					image = new Image(SeasonSummer); 
					break;
				case 2 : 
					image = new Image(SeasonAutomn);
					visible = false;break;
				case 3 :
					image = new Image(SeasonWinter);
					visible = false;break;
			}
			this.year = year;
			numSeason = num;
			
			graphic = image;
			//image.originY = image.height;
			x = FP.width / 2;
			y = FP.height;
			
			image.originX = image.width / 2;
			layer = 100;
			init = false;
		}
		
		public override function update():void
		{
			//trace("SEASON");//FP.world.getClass(Year, year);
			if (!init)
			{				
			FP.world.add(new Season2(this));
			init = true;
			}
			var lastAngle:Number;
			lastAngle = image.angle;
			if (!(FP.world as TreeWorld).paused)
			{
				image.angle = -(((numSeason + 1) * 180) + year.time * 360);
			}
			if (lastAngle%360<-180 && image.angle%360>-180)
			{
				visible = !visible;
				
			}
			/*visible = false;
			switch(numSeason)
			{
				case 0 : if ((year.time % 1.0) < (0.875) && (year.time % 1.0) > (0.375)) visible = false; break;
				case 1 : if ((year.time % 1.0) > (0.625) && (year.time % 1.0) < (0.125)) visible = false; break;
				case 2 : if ((year.time % 1.0) < (0.375) && (year.time % 1.0) > (0.875)) visible = false;break;
				case 3 : if ((year.time % 1.0) < (0.625) && (year.time % 1.0) > (0.125)) visible = false;break;
			}*/
			
		}
		
	}

}