These are some sweet functions ive made and i want to speed it up.
First one to do it gets a cookie 
Also tell me how i decrease the radius of a point on the minimap. (center of the circle being 247,85)
SCAR Code:
function MovePointCloser(Point: TPoint; Number :integer):TPoint;
var
ax,ay,ax2,ay2,bx,by:integer;
SqrRadius,Radius,CosAngle,TempAngle,SinAngle,Angle: extended;
begin
ax:= Point.X;
ay:= Point.Y;
ax2:= ax*ax;
ay2:= ay*ay;
SqrRadius:= ax2 + ay2;
radius:= sqrt(SqrRadius);
radius:= radius - number;
TempAngle:= ax/radius;
Angle:= radius*Cos(CosAngle);
CosAngle:= cos(Angle);
SinAngle:= sin(Angle);
bx:= round(radius*CosAngle);
by:= round(radius*SinAngle);
result:= inttopoint(bx,by);
end;
SCAR Code:
function CaveWalk(dir:string; modx,mody,FlagNum:integer):boolean;
var
i,Lengthen,NewOne,GreatestDist,Dist: Integer;
CenterPoint,ClickPoint: TPoint;
NTPA,STPA,ETPA,WTPA,NeTPA,NwTPA,SeTPA,SwTPA,BlackMM,WalkTPA: TPointArray;
Mark: LongInt;
begin
MarkTime(Mark);
CenterPoint:= inttopoint(627,85);
FindColorsTolerance(BlackMM,0,MMX1,MMY1,MMX2,MMY2,0);
for i:= 0 to length(BlackMM)-1 do
begin
if BlackMM[i].X < CenterPoint.X then
begin
if BlackMM[i].Y > CenterPoint.Y then
begin
lengthen:= length(SwTPA)+1;
SetArrayLength(SwTPA,lengthen);
newone:= Length(SwTPA)-1;
SwTPA[newone]:= BlackMM[i];
end;
if BlackMM[i].Y < CenterPoint.Y then
begin
lengthen:= length(NwTPA)+1;
SetArrayLength(NwTPA,lengthen);
newone:= Length(NwTPA)-1;
NwTPA[newone]:= BlackMM[i];
end;
end;
if BlackMM[i].X > CenterPoint.X then
begin
if BlackMM[i].Y < CenterPoint.Y then
begin
lengthen:= length(NeTPA)+1;
SetArrayLength(NeTPA,lengthen);
newone:= Length(NeTPA)-1;
NeTPA[newone]:= BlackMM[i];
end;
if BlackMM[i].Y > CenterPoint.Y then
begin
lengthen:= length(SeTPA)+1;
SetArrayLength(SeTPA,lengthen);
newone:= Length(SeTPA)-1;
SeTPA[newone]:= BlackMM[i];
end;
end;
if BlackMM[i].X = CenterPoint.X then
begin
if BlackMM[i].Y < CenterPoint.Y then
begin
lengthen:= length(NTPA)+1;
SetArrayLength(NTPA,lengthen);
newone:= Length(NTPA)-1;
NTPA[newone]:= BlackMM[i];
end;
if BlackMM[i].Y > CenterPoint.Y then
begin
lengthen:= length(STPA)+1;
SetArrayLength(STPA,lengthen);
newone:= Length(STPA)-1;
STPA[newone]:= BlackMM[i];
end;
end;
if BlackMM[i].Y = CenterPoint.Y then
begin
if BlackMM[i].X < CenterPoint.X then
begin
lengthen:= length(WTPA)+1;
SetArrayLength(WTPA,lengthen);
newone:= Length(WTPA)-1;
WTPA[newone]:= BlackMM[i];
end;
if BlackMM[i].X > CenterPoint.X then
begin
lengthen:= length(ETPA)+1;
SetArrayLength(ETPA,lengthen);
newone:= Length(ETPA)-1;
ETPA[newone]:= BlackMM[i];
end;
end;
end;
case lowercase(dir) of
'nw' : WalkTPA:= NwTPA;
'n' : WalkTPA:= NTPA;
'ne' : WalkTPA:= NeTPA;
'e' : WalkTPA:= ETPA;
'se' : WalkTPA:= SeTPA;
's' : WalkTPA:= STPA;
'sw' : WalkTPA:= SwTPA;
'w' : WalkTPA:= WTPA;
end;
for i:= 0 to length(WalkTPA)-1 do
begin
Dist:= Distance(WalkTPA[i].X,WalkTPA[i].Y,CenterPoint.X,CenterPoint.Y);
if Dist > GreatestDist then
begin
GreatestDist:= Dist;
ClickPoint:= WalkTPA[i];
end;
end;
repeat
ClickPoint:= MovePointCloser(ClickPoint,5);
until(Distance(ClickPoint.X,ClickPoint.Y,CenterPoint.X,CenterPoint.Y) < 68);
if not ClickPoint.X = 0 then
begin
result:= true;
Mouse(ClickPoint.X,ClickPoint.Y,modx,mody,true);
FFlag(FlagNum);
end;
writeln('Took '+inttostr(TimeFromMark(Mark))+' ms');
end;