This repository has been archived by the owner on Jan 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathHelper2.cs
58 lines (53 loc) · 1.85 KB
/
Helper2.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using Terraria;
using Terraria.ModLoader;
using System;
using Microsoft.Xna.Framework;
namespace Tremor
{
public static class Helper2
{
public static int GetNearestPlayer(Terraria.NPC npc)
{
float NearestPlayerDist = 4815162342f;
int NearestPlayer = -1;
foreach (Player player in Main.player)
{
if (player.Distance(npc.Center) < NearestPlayerDist)
{
NearestPlayerDist = player.Distance(npc.Center);
NearestPlayer = player.whoAmI;
}
}
return NearestPlayer;
}
public static int GetNearestAlivePlayer(Terraria.NPC npc)
{
float NearestPlayerDist = 4815162342f;
int NearestPlayer = -1;
foreach (Player player in Main.player)
{
if (player.Distance(npc.Center) < NearestPlayerDist && player.active)
{
NearestPlayerDist = player.Distance(npc.Center);
NearestPlayer = player.whoAmI;
}
}
return NearestPlayer;
}
public static Vector2 VelocityFPTP(Vector2 pos1, Vector2 pos2, float speed)
{
Vector2 move = pos2 - pos1;
return move * (speed / (float)Math.Sqrt(move.X * move.X + move.Y * move.Y));
}
public static Vector2 RandomPositin(Vector2 pos1, Vector2 pos2)
{
Random rnd = new Random();
return new Vector2(rnd.Next((int)pos1.X, (int)pos2.X) + 1, rnd.Next((int)pos1.Y, (int)pos2.Y) + 1);
}
public static float rotateBetween2Points(Vector2 point1, Vector2 point2)
{
float rotation = (float)Math.Atan2(point1.Y - (point2.Y), point1.X - (point2.X));
return rotation;
}
}
}