Coches con Array
Car[] myCars; int numCoches = 40; void setup() { size(800, 600); myCars = new Car[numCoches]; for (int i = 0; i < numCoches; i++) { color c = color(random(255), random(255), random(255)); float xpos = random(width-5); float ypos = random(height-5); float xspeed = random(-6, 6); if (xspeed == 0){ xspeed = 1;} myCars[i] = new Car(c, xpos, ypos, xspeed); } } void draw() { background(255); for (int i = 0; i < numCoches; i++) { myCars[i].drive(); myCars[i].display(); } } class Car { color c; float xpos; float ypos; float xspeed; Car(color tempC, float tempXpos, float tempYpos, float tempXspeed) { c = tempC; xpos = tempXpos; ypos = tempYpos; xspeed = tempXspeed; } void display() { ...