car.js
let xCars = [600, 600, 600];
let yCars = [40, 96, 150];
let vCars = [2.1, 3.2, 2.5];
function showCar() {
for (i = 0; i < imageCars.length; i++) {
image(imageCars[i], xCars[i], yCars[i], 50, 40);
}
}
function moveCar() {
for (i = 0; i < imageCars.length; i++) {
xCars[i] -= vCars[i];
}
}
function resetCar() {
for (i = 0; i < imageCars.length; i++) {
if (checkOffScreen(xCars[i])) {
xCars[i] = 600 - random(0, 100);
}
}
}
function checkOffScreen(xCar) {
return xCar < -50;
}