-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.cs
73 lines (61 loc) · 1.96 KB
/
Node.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
using System.Windows.Media.Imaging;
using System.Windows.Media;
namespace PathFinder
{
class Node
{
public Position screenPosition { get; set; }
public Position gridPosition { get; set; }
public int size { get; set; }
public int index { get; set; }
public NodeType type { get; set; } = NodeType.Empty;
private Color currentColor;
private Color animateToColor;
private bool shouldHandleAnimation = false;
public void Tick(float msElapsed) // Handle animation
{
if (!shouldHandleAnimation) return;
if (Color.AreClose(currentColor, animateToColor))
{
currentColor = animateToColor;
shouldHandleAnimation = false;
Draw();
return;
}
currentColor = currentColor.Lerp(animateToColor, msElapsed * 0.02f);
Draw();
}
public void SetType(NodeType newType, bool skipAnimation = false)
{
if (newType == type) return;
type = newType;
ResetColor(skipAnimation);
}
public void ResetColor(bool skipAnimation = false)
{
Color correctColor = type.ConvertTypeToColor( );
if(skipAnimation)
{
currentColor = correctColor;
shouldHandleAnimation = false;
Draw();
return;
}
if(correctColor != currentColor)
{
animateToColor = correctColor;
shouldHandleAnimation = true;
}
}
public void Draw()
{
Grid.Instance.surface.FillRectangle(screenPosition.X, screenPosition.Y, screenPosition.X + size, screenPosition.Y + size, currentColor);
}
}
}