-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTile.pde
109 lines (91 loc) · 2.34 KB
/
Tile.pde
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
public class Tile{
private boolean isOpen = false;
int posX, posY;
boolean hasNode = false;
Tile up, right, down, left;
Tile nodeUp, nodeRight, nodeDown, nodeLeft;
Tile parent;
int disUp, disRight, disDown, disLeft;
public Tile(int posX, int posY){
up = null;
right = null;
down = null;
left = null;
this.posX = posX;
this.posY = posY;
}
public void setOpen(boolean b){
isOpen = b;
if(up != null && up.isOpen) up.nodeCheck();
if(right != null && right.isOpen) right.nodeCheck();
if(left != null && left.isOpen) left.nodeCheck();
if(down != null && down.isOpen) down.nodeCheck();
if(b==false){
hasNode = false;
return;
}
nodeCheck();
}
public boolean isOpen(){
return isOpen;
}
public void nodeCheck(){
if(!isOpen) return;
hasNode = false;
int count = 0;
if(up != null && up.isOpen) count += 1;
if(right != null && right.isOpen) count+=2;
if(down != null && down.isOpen) count+= 4;
if(left != null && left.isOpen) count+= 8;
//Add a node for cases 1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 15
if(count != 0 && count != 5 && count != 10){
hasNode = true;
}
}
public void clearNodes(){
nodeUp = null;
nodeRight = null;
nodeDown = null;
nodeLeft = null;
disUp = 0;
disDown = 0;
disLeft = 0;
disRight = 0;
}
public Tile buildPathRight(){
if(right != null && right.isOpen && hasNode){
if(right.hasNode){
nodeRight = right;
}
else{
nodeRight = right.getNodeRight();
}
nodeRight.nodeLeft = this;
disRight = nodeRight.posX-posX;
nodeRight.disLeft = disRight;
}
return nodeRight;
}
public Tile buildPathUp(){
if(up!= null && up.isOpen && hasNode){
if(up.hasNode){
nodeUp = up;
}
else{
nodeUp = up.getNodeUp();
}
nodeUp.nodeDown = this;
disUp = posY-nodeUp.posY;
nodeUp.disDown = disUp;
}
return nodeUp;
}
public Tile getNodeRight(){
if(hasNode) return this;
return right.getNodeRight();
}
public Tile getNodeUp(){
if(hasNode) return this;
return up.getNodeUp();
}
}