-
Notifications
You must be signed in to change notification settings - Fork 10
/
VisualUtils.cs
82 lines (71 loc) · 2.91 KB
/
VisualUtils.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;
namespace MechTransfer
{
public static class VisualUtils
{
private const float dustVelocity = 1.5f;
private static MechTransfer mod = (MechTransfer)ModLoader.GetMod("MechTransfer");
public static void UnwindVisuals(Dictionary<Point16, byte> visited, Point16 startPoint)
{
Point16 p = startPoint;
while (visited.ContainsKey(p))
{
TransferAgent.Direction dir = (TransferAgent.Direction)visited[p];
visited[p] = (byte)TransferAgent.Direction.stop; //Stops multiple particles, if multiple containers receive
switch (dir)
{
case TransferAgent.Direction.up: p = new Point16(p.X, p.Y - 1); break;
case TransferAgent.Direction.down: p = new Point16(p.X, p.Y + 1); break;
case TransferAgent.Direction.left: p = new Point16(p.X - 1, p.Y); break;
case TransferAgent.Direction.right: p = new Point16(p.X + 1, p.Y); break;
case TransferAgent.Direction.stop: return;
}
if (Main.netMode == 0)
{
CreateVisual(p, dir);
}
else
{
ModPacket packet = NetRouter.GetPacketTo(ModContent.GetInstance<TransferAgent>(), mod);
packet.WritePackedVector2(p.ToVector2());
packet.Write((byte)dir);
packet.Send();
}
}
}
public static void CreateVisual(Point16 point, TransferAgent.Direction dir)
{
Vector2 location = new Vector2(point.X * 16 + 8, point.Y * 16 + 8);
Vector2 velocity = Vector2.Zero;
switch (dir)
{
case TransferAgent.Direction.up: velocity.Y = dustVelocity; break;
case TransferAgent.Direction.down: velocity.Y = -dustVelocity; break;
case TransferAgent.Direction.left: velocity.X = dustVelocity; break;
case TransferAgent.Direction.right: velocity.X = -dustVelocity; break;
case TransferAgent.Direction.stop: return;
}
Dust dust = Dust.NewDustPerfect(location, DustID.Silver, velocity);
dust.noGravity = true;
if (Main.xMas)
{
if (point.X % 2 == point.Y % 2)
dust.color = Color.Red;
else
dust.color = Color.LightGreen;
}
if (Main.halloween)
{
if (point.X % 2 == point.Y % 2)
dust.color = Color.MediumPurple;
else
dust.color = Color.Orange;
}
}
}
}