PriSoner
2008-02-18 17:13:09
I could find nothing similar within SRL so I wrote these 2 new small but hopefully useful functions.
Do with them as you will…
function CoordsToDegrees(x, y: integer): integer;
Returns the direction of x & y coordinates in degrees relative to the player.
This result can be used with functions like MakeCompass to make an object appear above the player in the play area.
procedure MakeCompassCoords(x, y: integer);
Just a simple combination of CoordsToDegrees and MakeCompass to make an object appear above the player in the play area.
I had noticed that quite often when performing tasks Talking Randoms would occasionally appear behind the object I was working on. This would mean that UpText would not detect the random. I wrote these to ensure that my player was always on the visible side of my target object, thus enabling better detection of randoms.
Updated 21-Feb-2008 to make Degrees Relative to North.
Do with them as you will…
function CoordsToDegrees(x, y: integer): integer;
Returns the direction of x & y coordinates in degrees relative to the player.
This result can be used with functions like MakeCompass to make an object appear above the player in the play area.
procedure MakeCompassCoords(x, y: integer);
Just a simple combination of CoordsToDegrees and MakeCompass to make an object appear above the player in the play area.
I had noticed that quite often when performing tasks Talking Randoms would occasionally appear behind the object I was working on. This would mean that UpText would not detect the random. I wrote these to ensure that my player was always on the visible side of my target object, thus enabling better detection of randoms.
Updated 21-Feb-2008 to make Degrees Relative to North.
{*******************************************************************************
function CoordsToDegrees(x, y: integer): integer;
By: PriSoner
Description: Returns the direction in degrees (0 to 359) to a set of coordinates
relative to your players position on the screen and North.
(degrees are in reverse to the convention to stay compatible with
MakeCompass etc i.e. 0 = N, 90 = W, 180 = S & 270 = E)
*******************************************************************************}
function CoordsToDegrees(x, y: integer): integer;
var d: double;
begin
x := x - 260;
y := y - 160;
d := ArcTan2(y, x) * (180 div Pi) + 90;
if d < 0 then d := d + 360;
result := round(abs(d - 360) + rs_GetCompassAngleDegrees);
if result >= 360 then result := result - 360;
end;
{*******************************************************************************
procedure MakeCompassCoords(x, y: integer);
By: PriSoner
Description: Moves Compass so that target x & y coordinates are directly north
of your player.
*******************************************************************************}
procedure MakeCompassCoords(x, y: integer);
begin
MakeCompass(IntToStr(CoordsToDegrees(x, y)));
end;