-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTP02.pde
More file actions
119 lines (89 loc) · 2.73 KB
/
Copy pathTP02.pde
File metadata and controls
119 lines (89 loc) · 2.73 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
//Constantes
final int tam_grid = 15;
final int num_barreiras = 60;
final int valor_robo = -2;
final int valor_destino = -3;
final int valor_barreira = 0;
final int valor_percorrido = -4;
//Matriz feita com hash
public HashMap<Cordenada, Integer> elementos = new HashMap<Cordenada, Integer>();
public LinkedList<Cordenada> melhor_caminho = new LinkedList<Cordenada>();
public int limite;
public boolean achou_destino = false;
//Variáveis do draw
int xRobo, yRobo;
int degrade;
float r, g, b;
color resultado = #B2B2B2; /*
* Começa com a mesma cor do background
* Achou caminho -> Verde
* Nao achou caminho -> Vermelho
*/
//Imagens
PImage DarthVader;
PImage StormTrooper;
PImage DeathStar;
PImage Yoda;
PImage YodaRush;
void setup(){
size (700, 700);
DarthVader = loadImage("darth_vader.png");
StormTrooper = loadImage("stormtrooper.png");
DeathStar = loadImage("estrela_da_morte.png");
Yoda = loadImage("yoda.png");
YodaRush = loadImage("yoda_avanço.png");
thread("executa");
}
void executa(){
Matriz matriz = new Matriz(tam_grid);
matriz.CriaMapa();
matriz.WaveFront();
matriz.Simulacao();
}
void draw(){
background(#FFFFFF);
stroke(#10029D);
float x, y;
int num_rects = limite;
float l = width / (float)num_rects;
float h = height / (float)num_rects;
for (int i = 0; i < num_rects; i++){
for (int j = 0; j < num_rects; j++){
Cordenada pos_rect = new Cordenada(i, j);
x = j * l;
y = i * h;
if (elementos.containsKey(pos_rect) && elementos.get(pos_rect) == valor_barreira){
fill(resultado);
rect(x, y, l, h);
image(StormTrooper, x, y, l, h);
} else if (elementos.containsKey(pos_rect) && elementos.get(pos_rect) == valor_destino){
fill(#B2B2B2);
rect(x, y, l, h);
image(DarthVader, x, y, l, h);
} else if (elementos.containsKey(pos_rect) && elementos.get(pos_rect) > 0){
degrade = elementos.get(pos_rect) * 7;
r = 255 - degrade / 0.85;
g = 0 + degrade;
b = 255 - degrade;
if (g > 22) g = 22;
fill(r, g, b);
rect(x, y, l, h);
if (tam_grid <= 15){
fill(255);
textAlign(CENTER, CENTER);
text(String.format("%d", elementos.get(pos_rect)), x + l / 2, y + h / 2);
}
} else if (elementos.containsKey(pos_rect) && elementos.get(pos_rect) == valor_percorrido){
fill(#E0FFDE);
rect(x, y, l, h);
} else {
fill(#B2B2B2);
rect(x, y, l, h);
}
}
}
//Anda com o ROBO
fill(#B2B2B2);
rect(xRobo * l, yRobo * h, l, h);
image(Yoda, xRobo * l, yRobo * h, l, h);
}