This repository was archived by the owner on Dec 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirection.cs
More file actions
61 lines (46 loc) · 1.72 KB
/
Direction.cs
File metadata and controls
61 lines (46 loc) · 1.72 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
using Microsoft.Xna.Framework;
namespace Techarria
{
public class Direction
{
public static readonly Direction Left = new(-1, 0);
public static readonly Direction Right = new(1, 0);
public static readonly Direction Up = new(0, -1);
public static readonly Direction Down = new(0, 1);
public Point point;
public int num;
public static Direction[] directions()
{
return new Direction[4] { new Direction(0), new Direction(1), new Direction(2), new Direction(3) };
}
public Direction(Point p)
{
point = p;
if (p.X == 1) num = 0;
if (p.X == -1) num = 2;
if (p.Y == 1) num = 1;
if (p.Y == -1) num = 3;
}
public static implicit operator Direction(Point p) => new(p);
public static implicit operator Point(Direction d) => d.point;
public Direction(int x, int y) => new Direction(new Point(x, y));
public Direction(int n)
{
num = n;
if (n == 0) point = new Point(1, 0);
if (n == 1) point = new Point(0, 1);
if (n == 2) point = new Point(-1, 0);
if (n == 3) point = new Point(0, -1);
}
public static implicit operator int(Direction d) => d.num;
public static implicit operator Direction(int n) => new(n);
public static implicit operator Vector2(Direction d) => new(d.point.X, d.point.Y);
public void Rotate(int steps)
{
Direction newDir = new Direction((num + steps) % 4);
num = newDir.num;
point = newDir.point;
}
public Direction Rotated(int steps) => new((num + steps) % 4);
}
}