Olá pessoal!
Segue a minha versão do código : https://editor.p5js.org/raphamass/sketches/wS4G0cBSp
E o arquivo car.js ficou assim:
/* Lane info:
Lane 1 = cars 1 and 7; Lane 2 = car 2; Lane 3 = car 3; Lane 4 = cars 4 and 8; Lane 5 = car 5; Lane 6 = cars 6 and 9
Car Colors:
Car 1 = Green; Car 2 = Black; Car 3 = Yellow
*/
// Car variables - 9 cars
let xCars = [600, 600, 600, 600, 600, 600, 1000, 975, 1000];
let yCars = [40, 96, 150, 210, 260, 310, 40, 210, 310];
let carSpeed = [2, 2.5, 3.2, 3.8, 4.2, 2.9, 2, 3.8, 2.9];
function showCar(){
for(let i = 0; i< imageCars.length; i += 1) {
image(imageCars[i], xCars[i], yCars[i], 50, 40);
}
}
function carMotion(){
for(let i = 0; i < imageCars.length; i += 1) {
xCars[i] -= carSpeed[i];
}
}
function carRestartPoint(){
for(let i = 0; i < imageCars.length; i += 1) {
if (passedWholeScreen(xCars[i])) {
xCars[i] = 600;
}
}
}
function passedWholeScreen (xCar) {
return xCar < -50;
}