xxxxxxxxxx
31
// código do carro
let xCarros = [600, -90, 600, 600, -90, -90];
let yCarros = [40, 96, 152, 212, 265, 318];
let velocidadeCarros = [2.5, 3.5, 2.9, 6.8, 5.5, 3.5];
let widthCarro = 50
let heightCarro = 40
function mostraCarro(){
for(let i = 0; i < imagemCarros.length; i = i + 1){
image(imagemCarros[i], xCarros[i], yCarros[i], widthCarro, heightCarro);
}
}
function movimentaCarro(){
xCarros[0] -= velocidadeCarros[0];
xCarros[1] += velocidadeCarros[1];
xCarros[2] -= velocidadeCarros[2];
xCarros[3] -= velocidadeCarros[3];
xCarros[4] += velocidadeCarros[4];
xCarros[5] += velocidadeCarros[5];
}
function voltaPosicaoInicialDoCarro(){
if (xCarros[0] < -50) xCarros[0] = 600;
if (xCarros[1] > 600) xCarros[1] = -90;
if (xCarros[2] < -50) xCarros[2] = 600;
if (xCarros[3] < -50) xCarros[3] = 600;
if (xCarros[4] > 600) xCarros[4] = -90;
if (xCarros[5] > 600) xCarros[5] = -90;
}