-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComponent.Position.cs
More file actions
130 lines (116 loc) · 4.02 KB
/
Component.Position.cs
File metadata and controls
130 lines (116 loc) · 4.02 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
namespace Hexeract.Component.Position
{
/// <summary>
/// Vector is a part of the Component as there will be Entities that has a direction,
/// for example Player, Item at ground, etc.
/// </summary>
struct Vector
{
public int X { get; set; }
public int Y { get; set; }
public int Z { get; set; }
/// <summary>
/// There is a constructor forced to overwrite the struct properties, this is
/// used in order to let the developer initialize vectors in an easier way.
/// </summary>
/// <param name="x">X direction of the vector</param>
/// <param name="y">Y direction of the vector</param>
/// <param name="z">Z direction of the vector</param>
public Vector(int x, int y, int z)
{
X = x;
Y = y;
Z = z;
}
public override string ToString() => $"Vector hash: {GetHashCode()}, Vector X: {X}, Vector Y: {Y}, Vector Z: {Z}";
public override bool Equals(object toCompare) => (toCompare is Vector && this == (Vector) toCompare) ? true : false;
public static bool operator ==(Vector first, Vector second) => (first.X == second.X && first.Y == second.Y && first.Z == second.Z) ? true : false;
public static bool operator !=(Vector first, Vector second) => !(first == second);
public static Vector operator +(Vector first, Vector toAdd)
{
first.X += toAdd.X;
first.Y += toAdd.Y;
first.Z += toAdd.Z;
return first;
}
public static Vector operator +(Vector first, (int x, int y, int z) toAdd)
{
first.X += toAdd.x;
first.Y += toAdd.y;
first.Z += toAdd.z;
return first;
}
public static Vector operator +(Vector first, int toAdd)
{
first.X += toAdd;
first.Y += toAdd;
first.Z += toAdd;
return first;
}
public static Vector operator -(Vector first, Vector toSub)
{
first.X -= toSub.X;
first.Y -= toSub.Y;
first.Z -= toSub.Z;
return first;
}
public static Vector operator -(Vector first, (int x, int y, int z) toSub)
{
first.X -= toSub.x;
first.Y -= toSub.y;
first.Z -= toSub.z;
return first;
}
public static Vector operator -(Vector first, int toSub)
{
first.X -= toSub;
first.Y -= toSub;
first.Z -= toSub;
return first;
}
public static Vector operator *(Vector first, Vector toScale)
{
first.X *= toScale.X;
first.Y *= toScale.Y;
first.Z *= toScale.Z;
return first;
}
public static Vector operator *(Vector first, (int x, int y, int z) toScale)
{
first.X *= toScale.x;
first.Y *= toScale.y;
first.Z *= toScale.z;
return first;
}
public static Vector operator *(Vector first, int toScale)
{
first.X *= toScale;
first.Y *= toScale;
first.Z *= toScale;
return first;
}
}
/// <summary>
/// Location is a part of the Component as blocks and other entities will have a location,
/// for example Player, Item at ground, etc.
/// </summary>
struct Location
{
public int X { get; set; }
public int Y { get; set; }
public int Z { get; set; }
/// <summary>
/// There is a constructor forced to overwrite the struct properties, this is
/// used in order to let the developer create locations in an easier way.
/// </summary>
/// <param name="x">X coordinate</param>
/// <param name="y">Y coordinate</param>
/// <param name="z">Z coordinate</param>
public Location(int x, int y, int z)
{
X = x;
Y = y;
Z = z;
}
}
}