generated from alura/modelo-vitrinedev
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcarro.js
31 lines (27 loc) · 823 Bytes
/
carro.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// CÓDIGO DO CARRO
//Criando listas para otimizar o código. Chama o elemento pelo índice.
let xCarros = [600, 600, 600, 600, 600, 600];
let yCarros = [40, 96, 150, 270, 210, 318];
let velocidadeCarros = [2.5, 3.2, 4, 4.5, 5, 7] ;
let comprimentoCarro = 50;
let alturaCarro = 40;
function mostraCarro(){
for (let i = 0; i < imagemCarros.length; i++){
image(imagemCarros[i], xCarros[i], yCarros[i], comprimentoCarro, alturaCarro);
}
}
function movimentaCarro() {
for (let i = 0; i < velocidadeCarros.length; i++){
xCarros[i] -= velocidadeCarros[i];
}
}
function voltaPosicaoInicialDoCarro() {
for(i = 0; i < imagemCarros.length; i++){
if (passouTodaATela(xCarros[i])){
xCarros[i] = 600;
}
}
}
function passouTodaATela(xCarro) {
return xCarro < -50;
}