package 
{
	import flash.geom.Point;
	import flash.text.TextFormat;
	
	/**
	 * ...
	 * @author 
	 */
	public class Global 
	{
		public static var seed : uint = 1;
		public static const WIDTH = 800;
		public static const HEIGHT = 400;
		public static var time_360 : Number = 0;	
  
		[Embed( source = '../lib/THALEIA_.TTF', 
				fontFamily = 'main', 
				fontWeight = 'normal', 
				fontStyle = 'normal', 
				mimeType = 'application/x-font', 
				advancedAntiAliasing='true', 
				embedAsCFF = 'false'
				)]
		private static var EMBEDDED_FONT:Class;	
						
		public static var font_main : TextFormat = new TextFormat();
		font_main.font = "main";
		font_main.size = 32;
		
		public static var game_started : Boolean = false;
		
		public static function RandomBySeed() : Number{
			seed = (seed * 16807) % 2147483647;
			return seed / 2147483647;
			//return Math.random();
		}
		
		public static function Aspire(s : Number, aim  : Number, speed : Number) : Number{		
			var b : Boolean = true;
			
			if (s + speed < aim) {s += speed; b = false;}
			if (s - speed > aim) {s -= speed; b = false;}			
			if (b) s = aim;
			
			return s;
			//return b;
		}	
		
		
		public static function AspireSqr(s : Number, aim  : Number, speed : Number, minimum : Number = -1) : Number{
			var t : Number;
			t = Math.abs(s - aim);
			if (t < minimum / speed) 
				t = minimum / speed;
				
			return Aspire(s, aim, speed * t);		
		}
		
		public static function AspireAngle(s : Number, aim  : Number, speed : Number) : Number{
			var aim2 : Number = aim + 360;
			var aim3 : Number = aim - 360;

			if ((Math.abs(aim2 - s) < Math.abs(aim - s)) && (Math.abs(aim2 - s) < Math.abs(aim3 - s)))
				aim = aim2;
			else
				if ((Math.abs(aim3 - s) < Math.abs(aim - s)) && (Math.abs(aim3 - s) < Math.abs(aim2 - s)))
					aim = aim3;

			return Aspire(s, aim, speed);
		}
		
		public static function NormalizeAngle(a : Number) : Number {
			if (a < -Math.PI) 
				return Math.PI * 2 + a;
			if (a > Math.PI)
				return a - Math.PI * 2;
			return a;
		}

		public static function Sqr(a : Number) : Number {
			return a * a;
		}
		
		public static function RGB(r : uint, g : uint, b : uint) : uint {
			return (( r << 16 ) | ( g << 8 ) | b );
		}
	}
	
}