package Mobs
{
	import MapObjects.Building;
	
	/**
	 * ...
	 * @author Michael Miriti
	 */
	public class Pigeon extends Mob
	{
		private var _spooked:Boolean = false;
		private var _building:Building;
		private var _timing:Number = 0;
		private var _f:Boolean = false;
		
		public function Pigeon()
		{
			super();
		
		}
		
		public function spook():void
		{
			_spooked = true;
		}
		
		override public function update(delta:Number):void
		{
			super.update(delta);
			if (_spooked)
			{
				fy -= (delta / 1000) * (15 + Math.random() * 10);
				fx += -0.5 + Math.random() * 3;
				
				if (y < 0)
					MapManager.inst.delMob(this);
				
				if (_timing > 100)
				{
					_f = !_f;
					_timing = 0;
				}
				else
				{
					_timing += delta;
				}
			}
			else if ((Math.abs(x - MapManager.inst.player.x) <= 7) && (Math.abs(y - MapManager.inst.player.y) <= 4))
				_building.spookPigeons();
		}
		
		override public function render(delta:Number):void
		{
			super.render(delta);
			var px:int = x - MapManager.inst.shiftX;
			var py:int = y - MapManager.inst.shiftY;
			
			if (_spooked)
			{
				if (_f)
				{
					Main.i.setChar(px, py, "a".charCodeAt(0) - 1, 15, Main.i.getBack(px, py));
					if (px >= 1)
						Main.i.setChar(px - 1, py, "\\".charCodeAt(0) - 1, 15, Main.i.getBack(px - 1, py));
					if (px < 79)
						Main.i.setChar(px + 1, py, "/".charCodeAt(0) - 1, 15, Main.i.getBack(px + 1, py));
				}
				else
				{
					Main.i.setChar(px, py, "a".charCodeAt(0) - 1, 15, Main.i.getColor(px, py));
					if (px >= 1)
						Main.i.setChar(px - 1, py, "/".charCodeAt(0) - 1, 15, Main.i.getColor(px - 1, py));
					if (px < 79)
						Main.i.setChar(px + 1, py, "\\".charCodeAt(0) - 1, 15, Main.i.getColor(px + 1, py));
				}
			}
			else
				Main.i.setChar(px, py, "a".charCodeAt(0) - 1, 15, Main.i.getColor(px, py));
		}
		
		public function set building(value:Building):void
		{
			_building = value;
		}
	}

}