package  
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.geom.Point;
	
	/**
	 * ...
	 * @author beisik
	 */
	public class Pebble extends Sprite 
	{
		[Embed(source = 'textures/st1.png')] private const PEBBLE1: Class;
		[Embed(source = 'textures/st2.png')] private const PEBBLE2: Class;
		
		public var radius: Number;
		public var velocity: Point;
		
		public var active: Boolean;
		
		public function Pebble(x: Number, y: Number, small: Boolean) 
		{
			this.x = x;
			this.y = y;
			
			velocity = new Point();
			
			active = false;
			
			if (small)
			{
				var img: Bitmap = new PEBBLE2();
				radius = 2.5;
			}
			else
			{
				img = new PEBBLE1();
				radius = 5;
			}
			img.x = -img.width / 2;
			img.y = -img.height / 2;
			addChild(img);
			
			rotation = Math.random() * 180;
		}
		
		public function Update(dt: Number): void
		{
			x += velocity.x * dt;
			y += velocity.y * dt;
			
			velocity.x = Global.Aspire(velocity.x, 0, Snake.speed * dt);
			velocity.y = Global.Aspire(velocity.y, 0, Snake.speed * dt);
			
			rotation += velocity.length * dt;
			
			if (velocity.x == 0 && velocity.y == 0)
				active = false;
		}
		
		public function collideSnake(snake: Snake): void
		{			
			if (Global.Distance(x, y, snake.x, snake.y) < radius + Snake.radius * 2)
			{
				velocity = Global.Speed(snake.x, snake.y, x, y);
				velocity.x *= Snake.speed * 0.8;
				velocity.y *= Snake.speed * 0.8;
				active = true;
			}
		}
		
	}

}