-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathNode.cs
executable file
·93 lines (85 loc) · 2.54 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* Represent a single node in the pathfinding grid.
* Based on code and tutorial by Sebastian Lague (https://www.youtube.com/channel/UCmtyQOKKmrMVaKuRXz02jbQ).
*
* Author: Ronen Ness.
* Since: 2016.
*/
namespace NesScripts.Controls.PathFind
{
/// <summary>
/// Represent a single node in the pathfinding grid.
/// </summary>
public class Node
{
// is this node walkable?
public bool walkable;
public int gridX;
public int gridY;
public float price;
// calculated values while finding path
public int gCost;
public int hCost;
public Node parent;
/// <summary>
/// Create the grid node.
/// </summary>
/// <param name="_price">Price to walk on this node (set to 1.0f to ignore).</param>
/// <param name="_gridX">Node x index.</param>
/// <param name="_gridY">Node y index.</param>
public Node(float _price, int _gridX, int _gridY)
{
walkable = _price != 0.0f;
price = _price;
gridX = _gridX;
gridY = _gridY;
}
/// <summary>
/// Create the grid node.
/// </summary>
/// <param name="_walkable">Is this tile walkable?</param>
/// <param name="_gridX">Node x index.</param>
/// <param name="_gridY">Node y index.</param>
public Node(bool _walkable, int _gridX, int _gridY)
{
walkable = _walkable;
price = _walkable ? 1f : 0f;
gridX = _gridX;
gridY = _gridY;
}
/// <summary>
/// Updates the grid node.
/// </summary>
/// <param name="_price">Price to walk on this node (set to 1.0f to ignore).</param>
/// <param name="_gridX">Node x index.</param>
/// <param name="_gridY">Node y index.</param>
public void Update(float _price, int _gridX, int _gridY) {
walkable = _price != 0.0f;
price = _price;
gridX = _gridX;
gridY = _gridY;
}
/// <summary>
/// Updates the grid node.
/// </summary>
/// <param name="_walkable">Is this tile walkable?</param>
/// <param name="_gridX">Node x index.</param>
/// <param name="_gridY">Node y index.</param>
public void Update(bool _walkable, int _gridX, int _gridY) {
walkable = _walkable;
price = _walkable ? 1f : 0f;
gridX = _gridX;
gridY = _gridY;
}
/// <summary>
/// Get fCost of this node.
/// </summary>
public int fCost
{
get
{
return gCost + hCost;
}
}
}
}