Special Ed
2008-04-17 22:24:50
Sorts TPA by it's Distance from (Cx, Cy). It's got a wide range of uses, I developed this with the intention of finding the closest rock to your RS character but I've envisioned many more possibilities, and I'm sure the great minds of SRL will think of even more!
From what I've seen there isn't anything like it… there are things that are similar but nothing I've found can do this. Although, I'm pretty unobservant so who knows :p
procedure SortTPADist(var TPA: TPointArray; Cx, Cy: Integer);
var
ID: TPointArray;
i, ArrL: Byte;
begin
ArrL:= GetArrayLength(TPA);
SetArrayLength(ID, ArrL);
for i:= 0 to ArrL - 1 do
begin
ID[i].x:= Distance(Cx, Cy, TPA[i].x, TPA[i].y);
ID[i].y:= i;
end;
ID:= RearrangeTPA(ID, 0, ArrL, True, False);
for i:= 0 to ArrL - 1 do TPA[i]:= TPA[ID[ArrL - 1 - i].y];
end;
From what I've seen there isn't anything like it… there are things that are similar but nothing I've found can do this. Although, I'm pretty unobservant so who knows :p