Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
WorldUIAnchor.cs
Go to the documentation of this file.
1using System;
3
5
6public class WorldUIAnchor
7{
8 public enum AnchorType
9 {
10 Entity,
11 Tile,
12 Pos,
13 None
14 }
15
17
18 public Entity entity;
19
21
23
25 {
26 type = AnchorType.None;
27 }
28
29 public WorldUIAnchor(Entity anchor)
30 {
31 type = AnchorType.Entity;
32 entity = anchor;
33 }
34
35 public WorldUIAnchor(Vector2 anchor)
36 {
37 type = AnchorType.Pos;
38 pos = anchor;
39 }
40
41 public WorldUIAnchor(int topLeftX, int topLeftY, int width, int height)
42 {
43 type = AnchorType.Tile;
44 pos = new Vector2((float)topLeftX + (float)width / 2f, (float)topLeftY + (float)height / 2f) * 16f;
45 size = new Vector2(width, height) * 16f;
46 }
47
48 public bool InRange(Vector2 target, float tileRangeX, float tileRangeY)
49 {
50 switch (type)
51 {
52 case AnchorType.Entity:
53 if (Math.Abs(target.X - entity.Center.X) <= tileRangeX * 16f + (float)entity.width / 2f)
54 {
55 return Math.Abs(target.Y - entity.Center.Y) <= tileRangeY * 16f + (float)entity.height / 2f;
56 }
57 return false;
58 case AnchorType.Pos:
59 if (Math.Abs(target.X - pos.X) <= tileRangeX * 16f)
60 {
61 return Math.Abs(target.Y - pos.Y) <= tileRangeY * 16f;
62 }
63 return false;
64 case AnchorType.Tile:
65 if (Math.Abs(target.X - pos.X) <= tileRangeX * 16f + size.X / 2f)
66 {
67 return Math.Abs(target.Y - pos.Y) <= tileRangeY * 16f + size.Y / 2f;
68 }
69 return false;
70 default:
71 return true;
72 }
73 }
74}
static double Abs(double value)
Vector2 Center
Definition Entity.cs:43
bool InRange(Vector2 target, float tileRangeX, float tileRangeY)
WorldUIAnchor(int topLeftX, int topLeftY, int width, int height)