package game.GameMain
{
	import flash.display.Bitmap;
	import flinjin.Flinjin;
	import flinjin.graphics.Layer;
	import flinjin.graphics.Sprite;
	
	/**
	 * ...
	 * @author Michael Miriti <m.s.miriti@gmail.com>
	 */
	public class BackgroundLight extends Layer
	{
		[Embed(source="../../assets/light_1.png")]
		private static var _light1Bmp:Class;
		
		[Embed(source="../../assets/light_2.png")]
		private static var _light2Bmp:Class;
		
		private var _scrollY:Number = 0;
		static private const LIGHTS_COUNT:Number = 5;
		static private const LIGHT_HEIGHT:Number = 455;
		static public const GLOWWORMS_COUNT:uint = 20;
		
		private var _lights:Vector.<Sprite> = new Vector.<Sprite>;
		
		private function addLight():void
		{
			var newY:int = 0;
			
			var newBmp:Class;
			
			if (Math.random() > 0.5)
			{
				newBmp = _light1Bmp;
			}
			else
			{
				newBmp = _light2Bmp;
			}
			
			var newLight:Sprite = new Sprite(new newBmp() as Bitmap);
			
			if (_lights.length > 0)
			{
				var _last:Sprite = _lights[_lights.length - 1];
				newY = _last.y - newLight.height; // - newLight.height * (Math.random() * 2);
			}
			
			if (Math.random() < 0.5)
				newLight.flipHorizontal = true;
			
			addSprite(newLight, 0, newY);
			_lights.push(newLight);
		}
		
		override public function Move():void
		{
			for (var i:int = _lights.length - 1; i >= 0; i--)
			{
				if (_lights[i].y + _layerShift.y > Flinjin.sceneHeight)
				{
					deleteSprite(_lights[i]);
					_lights.splice(i, 1);
					addLight();
				}
			}
			super.Move();
		}
		
		public function BackgroundLight()
		{
			super(Flinjin.sceneWidth, Flinjin.sceneHeight);
			
			addLight();
			addLight();
			addLight();
			
			for (var i:int = 0; i < GLOWWORMS_COUNT; i++) 
			{
				var newGlowWorm:Glowworm = new Glowworm();
				newGlowWorm.x = 20 + Math.random() * 440;
				newGlowWorm.y = Math.random() * 640;
				addSprite(newGlowWorm);
			}
		}
	}

}
import flash.display.Bitmap;
import flash.geom.Point;
import flinjin.graphics.Layer;
import flinjin.graphics.Sprite;

class Glowworm extends Sprite
{
	[Embed(source="../../assets/swetkyachok.png")]
	private static var _glowwormBmp:Class;
	
	override public function Move():void
	{
		if ((_parentSprite as Layer).shiftY + y > 640) {
			y -= 650 + Math.random() * 300;
			x = 20 + Math.random() * 440;
		}
		y += 1;
		super.Move();
	}
	
	function Glowworm()
	{
		super(new _glowwormBmp() as Bitmap, new Point(8.5, 8), true, 17, 16, 1 / 10);
		currentFrame = Math.floor(Math.random() * 3);
	
	}
}