-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPipe_networks.pde
More file actions
216 lines (208 loc) · 5.23 KB
/
Pipe_networks.pde
File metadata and controls
216 lines (208 loc) · 5.23 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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import g4p_controls.*;
//types of pipes || value in cells
//straight pipe
PImage straight_pipe; // 1
//90degree turn
PImage curved_pipe; // 2
//intersection
PImage three_pipe; // 3
PImage four_pipe; // 4
//eraser
PImage erase;
PImage water_start;
PImage water_end;
PImage oil_start;
PImage oil_end;
String scene = "homescreen"; // scene being drawn
int [][] cells;//stores two digit values the first is the object the second is orintation
int [][] flow_path;//stores the start and end of pipeline
String pipe_type = "none";
int cursor_x;
int cursor_y;
//demo maps to test with
int[][] sample1 = {{0,20,20,20,20},{10,20,20,20,10},{0,0,20,20,10},{0,20,20,10,10},{20,20,0,20,20}};
int[][] sample1flow = {{0,0,0,0,0},{0,1,0,0,0},{-1,0,0,0,0},{0,0,0,0,0}};
int[][] sample2 = {
{00,00,00,00,00,20,20,00},
{00,00,20,20,00,20,20,00},
{00,20,20,20,20,20,20,00},
{00,20,20,20,20,20,00,00},
{00,20,20,20,20,00,00,00},
{00,20,20,00,00,00,00,00},
{00,20,20,00,00,00,00,00},
{00,20,20,00,00,00,00,00},
{00,20,20,00,00,00,00,00}};
int[][] sample2flow= {
{0,0,0,0,0,0,1,0},
{0,0,0,0,0,0,0,0},
{0,0,-1,0,0,0,0,0},
{0,0,0,0,0,0,0,0}};
int homescreen_background_image = int(random(0,4));
color background_color = color(random(150,255),random(150,255),random(150,255));
void setup(){
cells = new int [canvas_definition][canvas_definition];
for(int i = 0; i<canvas_definition; i++){
for(int j = 0; j<canvas_definition; j++){
cells[i][j] = 0;
}
}
flow_path = new int[4][canvas_definition];
canvas_definition = 5;
imageMode(CENTER);
size(600,600);
createGUI();
window1.setVisible(false);// makes the tool bar hidden on start up
loadImages();
frameRate(60);
}
void loadImages(){
straight_pipe = loadImage("straight_pipe.png");
curved_pipe = loadImage("curved_pipe.png");
three_pipe = loadImage("3waypipe.png");
four_pipe = loadImage("4waypipe.png");
erase = loadImage("erase.png");
water_start = loadImage("water_start.png");
water_end = loadImage("water_end.png");
oil_start = loadImage("oil_start.png");
oil_end = loadImage("oil_end.png");
}
int r = 0; // allows the solution to be displayed step by step
int animation_speed = 5;//min speed = 1, max speed = 10
String algo = "basic";
void draw(){
background(background_color);
switch(scene){
case "homescreen":
switch(homescreen_background_image){
case 0:
image(straight_pipe,width/2,height/2,width,height);
break;
case 1:
image(curved_pipe,width/2,height/2,width,height);
break;
case 2:
image(three_pipe,width/2,height/2,width,height);
break;
case 3:
image(four_pipe,width/2,height/2,width,height);
break;
}
break;
case "build mode":
draw_grid();
place_pipes();
break;
case "computer solving puzzle":
animate_solution();
break;
}
}
void animate_solution(){
draw_grid();
if(verified && r<100){
fill(0,255,0);
textSize(50);
textAlign(CENTER);
text("Solved",width/2,height/2);
fill(255);
r++;
}
else if(!solution_found && r<100){
fill(255,0,0);
textSize(50);
textAlign(CENTER);
text("No Path Found",width/2,height/2);
fill(255);
r++;
}
else if(solution_found && r<100*path.size()){
if(r<100*animation_speed){
fill(0,255,0);
textSize(50);
textAlign(CENTER);
text("Path Found",width/2,height/2);
fill(255);
}
solve(path.get(r/100));
r+=animation_speed;
}
else{
scene = "build mode";
path.clear();
solution_found = false;
solving=false;
}
}
int cur_liquid;
int object_being_placed;
int cur_image = 0;
int cur_orientation = 0;
void place_pipes(){
switch(pipe_type){
case "delete":
cur_image = 0;
image(erase, mouseX, mouseY, 50, 50);
break;
case "Straight":
cur_image = 1;
change_rotation();
image(straight_pipe, cursor_x, cursor_y, 50, 50);
break;
case "Bend":
cur_image = 2;
change_rotation();
image(curved_pipe, cursor_x, cursor_y, 50, 50);
break;
case "3 Way":
cur_image = 3;
change_rotation();
image(three_pipe, cursor_x, cursor_y, 50, 50);
break;
case "4 Way":
cur_image = 4;
change_rotation();
image(four_pipe, cursor_x, cursor_y, 50, 50);
break;
case "water start":
cur_liquid = 1;
image(water_start, mouseX, mouseY, 50, 50);
break;
case "water end":
cur_liquid = -1;
image(water_end, mouseX, mouseY, 50, 50);
break;
case "oil start":
cur_liquid = 2;
image(oil_start, mouseX, mouseY, 50, 50);
break;
case "oil end":
cur_liquid = -2;
image(oil_end, mouseX, mouseY, 50, 50);
break;
}
}
void change_rotation(){
rotate(cur_orientation*PI/2);
switch(cur_orientation){
case 0:
cursor_x = mouseX;
cursor_y = mouseY;
break;
case 1:
cursor_x = mouseY;
cursor_y = -mouseX;
break;
case 2:
cursor_x = -mouseX;
cursor_y = -mouseY;
break;
case 3:
cursor_x = -mouseY;
cursor_y = mouseX;
break;
}
}
//To Do:
//bottom right and bottom left click doesn't produce expected behaviour.
//start on the solving algo don't be lazy
//fix gimicky controls