package  
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	
	/**
	 * ...
	 * @author beisik
	 */
	public class Apple extends Sprite 
	{
		public static const RADIUS: Number = 27;
		
		[Embed(source = 'textures/a1.png')] private const APPLE1: Class;
		[Embed(source = 'textures/a2.png')] private const APPLE2: Class;
		[Embed(source = 'textures/a3.png')] private const APPLE3: Class;
		
		public var alive: Boolean;
		
		public var shadow: Shadow;
		
		public function Apple(level: Level) 
		{
			x = 30 + Math.random() * (Game.Width - 60) + level.x;
			y = 30 + Math.random() * (Game.Height - 60) + level.y;
			
			var i: uint = 0;
			while (i < level.rocks.length)
			{
				if (Global.Distance(x, y, level.rocks[i].x, level.rocks[i].y) <= 15 + level.rocks[i].radius)
				{
					x = 30 + Math.random() * (Game.Width - 60) + level.x;
					y = 30 + Math.random() * (Game.Height - 60) + level.y;
					i = 0;
				}
				else
					i++;
			}
			
			alive = true;
			
			i = Math.round(Math.random() * 2);
			var img: Bitmap;
			switch (i)
			{
				case 0: img = new APPLE1; break;
				case 1: img = new APPLE2; break;
				case 2: img = new APPLE3; break;
			}
			img.x = -30;
			img.y = -30;
			addChild(img);
			
			shadow = new Shadow(1);
			shadow.move(x, y);
			
			/*graphics.lineStyle(2, 0xFFFFFF);
			graphics.beginFill(0, 0.5);
			graphics.drawCircle(0, 0, RADIUS);
			graphics.endFill();*/
		}
		
	}

}