PFont font;
ArrayList<walkers> l = new ArrayList<walkers>();
ArrayList<walkers> i = new ArrayList<walkers>();
ArrayList<walkers> L = new ArrayList<walkers>();
int mongolicos = 10;
int proteccion = 5;
int infectado_proteccion = 0;
int infectado_mongolico = 0;
int recuperados = 0;
int muertos = 0;
void setup() {
size(500, 200);
font=loadFont("AgencyFB-Bold-48.vlw");
textFont(font);
for (int j = 0; j < 10; j++) {
l.add(new walkers('l'));
}
for (int n = 0; n < 5; n++) {
l.add(new walkers('L'));
}
i.add(new walkers('i'));
}
void draw() {
background(120);
for (int n = 0; n < L.size(); n++) {
L.get(n).dibujar();
L.get(n).mover();
L.get(n).detectarBordes();
for (int k = 0; k < L.size(); k++) {
if (k != n) {
L.get(n).interactuar(L.get(n), L.get(k));
}
if (i.size() > 0) {
L.get(n).interactuar(L.get(n), i.get(0));
}
if (L.get(n).recovery_dead() == 'd') {
L.remove(L.get(n));
infectado_proteccion--;
muertos++;
}
}
}
for (int j = 0; j < l.size(); j++) {
l.get(j).dibujar();
l.get(j).mover();
l.get(j).detectarBordes();
for (int k = 0; k < l.size(); k++) {
if (k != j) {
l.get(j).interactuar(l.get(j), l.get(k));
}
if (i.size() > 0) {
l.get(j).interactuar(l.get(j), i.get(0));
}
if (l.get(j).recovery_dead() == 'd') {
l.remove(l.get(j));
infectado_mongolico--;
muertos++;
}
}
}
if (i.size() > 0) {
i.get(0).dibujar();
i.get(0).mover();
i.get(0).detectarBordes();
if (i.get(0).recovery_dead() == 'd') {
i.remove(i.get(0));
muertos++;
}
}
fill(255);
textSize(17);
text("Sin Proteccion ="+mongolicos, 320,30);
text("Con Proteccion ="+ proteccion, 320,70);
text("Infectado_Sin Protección ="+ infectado_mongolico, 300,100);
text("Infectado_Proteccion ="+ infectado_proteccion, 300,140);
text("Recuperados ="+ recuperados, 320,170);
text("Muertos="+muertos,320,200);
}
class walkers {
float h, k, d, vX, vY, time_i;
char E;
color Color;
walkers(char estado) {
d = 10;
h = random(d / 2, width - (height + d / 2));
k = random(d / 2, height - (d / 2));
vX = random(-1.5, 1.5);
vY = random(-1.5, 1.5);
E = estado;
if (E == 'l' || E == 'L') {
Color = 255;
} else if (E == 'i' || E == 'I') {
Color = #E0663D;
} else if (E == 'r') {
Color = #4DD376;
recuperados ++;
}
}
walkers(float pX, float pY, float diameter, float velX, float velY, color C) {
h = pX;
k = pY;
d = diameter;
vX = velX;
vY = velY;
Color = C;
}
void dibujar() {
if(E == 'L' || E == 'I'){
noFill();
stroke(200);
ellipse(h, k, 3 * d / 2, 3 * d / 2);
fill(Color);
noStroke();
ellipse(h,k,d,d);
} else if( E == 'l' || E == 'i'){
fill(Color);
noStroke();
ellipse(h, k, d, d);
}
}
void mover() {
h += vX;
k += vY;
h = constrain(h, d / 2, width - (height + d / 2));
k = constrain(k, d / 2, height - (d / 2));
}
void detectarBordes() {
if (h + d / 2 >= width - height || h - d / 2 <= 0) {
vX = -vX;
} else if (k - d / 2 <= 0 || k + d / 2 >= height) {
vY = -vY;
}
}
void interactuar(walkers w1, walkers w2) {
float w1VX = w1.vX;
float w1VY = w1.vY;
float w2VX = w2.vX;
float w2VY = w2.vY;
float R;
if (dist(w1.h, w1.k, w2.h, w2.k) <= w1.d / 2 + w2.d / 2 //
&& ((w1.E == 'l' && w2.E == 'i')//
|| (w1.E == 'l' && w2.E == 'l')//
|| (w1.E == 'i' && w2.E == 'l')//
|| (w1.E == 'i' && w2.E == 'i'))) {
w1.vX = w2VX;
w1.vY = w2VY;
w2.vX = w1VX;
w2.vY = w1VY;
R = random(100);
if (w1.E == 'l' && w2.E == 'i' && R > 95) {
w1.E = 'i';
mongolicos --;
infectado_mongolico++;
w1.Color = #FA47E8;
time_i = millis();
}
}else if ( dist (w1.h, w1.k, w2.h, w2.k) <= w1.d / 2 + 3 * w2.d / 4//
&& ((w1.E == 'l' && w2.E == 'L') //
|| (w1.E == 'i' && w2.E == 'L')//
|| (w1.E == 'l' && w2.E == 'I'))) {
w1.vX = w2VX;
w1.vY = w2VY;
w2.vX = w1VX;
w2.vY = w1VY;
R = random(100);
if ((w1.E == 'i' && w2.E == 'L') || (w1.E == 'L' && w2.E == 'i')//
&& R < 0.02 ){
w2.E = 'I';
proteccion--;
infectado_proteccion++;
w2.Color = #FA47E8;
time_i = millis();
}
}
else if ( dist (w1.h, w1.k, w2.h, w2.k) <= 3 * w1.d / 4 + 3 * w2.d / 4//
&& ((w1.E == 'L' && w2.E == 'L') //
|| (w1.E == 'I' && w2.E == 'L')//
|| (w1.E == 'L' && w2.E == 'I')//
|| (w1.E == 'I' && w2.E == 'I'))) {
w1.vX = w2VX;
w1.vY = w2VY;
w2.vX = w1VX;
w2.vY = w1VY;
R = random(100);
if (w1.E == 'L' && w2.E == 'I' && R > 0.05 ){
w2.E = 'I';
proteccion--;
infectado_proteccion++;
w2.Color = #FA47E8;
time_i = millis();
}
}
}
char recovery_dead() {
float R = random(100);
if ((E == 'i'|| E == 'I') && millis() > time_i + 30000 && R > 0.09) {
E = 'd';
return E;
} else if ((E == 'i'|| E == 'I' ) && millis() > time_i + 30000 && R > 10) {
E = 'r';
Color = #3DD85B;
return E;
}else {
return ' ';
}
}
}
L is empty, you haven’t defined it in setup()