package  
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import interfaces.IGameObject;
	
	/**
	 * ...
	 * @author Fiodar Paulavets
	 */
	public class Cloud extends Sprite implements IGameObject 
	{
		private var _speed: Number;
		private var _front: Boolean;
		
		public function Cloud(front: Boolean) 
		{
			_front = front;
			
			var clip: MovieClip;
			var r: uint = Math.round(Math.random() * 3);
			switch (r)
			{
				case 0: clip = new Cloud1Clip(); break;
				case 1: clip = new Cloud2Clip(); break;
				case 2: clip = new Cloud3Clip(); break;
				case 3: clip = new Cloud4Clip(); break;
			}
			if (!front)
				clip.scaleX = clip.scaleY = 0.6 + Math.random() * 0.4;
			else
				clip.scaleX = clip.scaleY = 1 + Math.random() * 0.5;
			addChild(clip);
			
			var ky: Number = Math.random();
			
			if (!front)
				clip.alpha = 0.5 + ky * 0.3;
			else
				clip.alpha = 0.8;
			
			x = Game.screenWidth + Math.random() * 70;
			y = Math.random() * 250;
			_speed = 70;
			if (!front)
				_speed = _speed / 2 * (1 + ky);
			else
				_speed *= 2;
		}
		
		/* INTERFACE interfaces.IGameObject */
		
		public function Update(dt:Number):void 
		{
			x -= _speed * dt;
			
			if (x + width < 0)
				if (!_front)
					World.world.backClouds.remove(this);
				else
					World.world.frontClouds.remove(this);
		}
		
	}

}