Author Topic: Comparing Range of Two Objects  (Read 2849 times)

0 Members and 1 Guest are viewing this topic.

Offline playforfunTopic starter

  • Restricted
  • **
  • Posts: 28
  • Activity:
    0%
  • Reputation Power: 1
  • playforfun has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
Comparing Range of Two Objects
« on: August 13, 2016, 07:26:31 PM »
0
I wasn't sure if there was an API to compare two objects distances from one another, I know you can search an objects range from your self with FindDistance; ...

Either way I came up with my own version so I would like to share it with you guys if you ever find you need to compare the distance between two objects.

Example:

Check if Chest2 is within 2 tiles of Chest1...

Code: [Select]
Program Example;

Type
    TileCord = record
        x, y : Integer
    end;

Var
   TileRange : Array of TileCord;

Function SeekRange(ObjOne, ObjTwo : Cardinal; Range : Integer) : Boolean;

Var

x, y, i : Integer;

begin

Result:= False;
SetLength(TileRange, 0);
 for x := (-1 * Range) to Range do      
  for y := (-1 * Range) to Range do
  begin
   SetLength(TileRange, Length(TileRange) + 1);
   TileRange[High(TileRange)].x := (GetX(ObjOne) + x);
   TileRange[High(TileRange)].y := (GetY(ObjOne) + y);
  end;
for i := Low(TileRange) to High(TileRange) do  
 if TileRange[i].x = (GetX(ObjTwo)) then
  for i := Low(TileRange) to High(TileRange) do
   if TileRange[i].y = (GetY(ObjTwo)) then
    Result := True;
            
end;

//Main Body
begin
 if SeekRange(Chest1, Chest2, 2) = True then
 // what you want it to do =)
end.
« Last Edit: August 13, 2016, 07:30:25 PM by playforfun »

Tags: