-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcarros.js
More file actions
43 lines (36 loc) · 928 Bytes
/
Copy pathcarros.js
File metadata and controls
43 lines (36 loc) · 928 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
43
//Posição dos Carros
let xCarros = [630, 630, 630, -30, -30, -30];
let yCarros = [45, 100, 156, 216, 266, 326];
let veloCarros = [4, 3.5, 4.2, 3, 4.5, 3.7];
//Tamanho dos Carros
let larguraCarro = 50;
let alturaCarro = 30;
//Posições dos extremos
let posicaoDireita = 630;
let posicaoEsquerda = -30;
//Funções de Movimenta Carro
function mostraCarro(){
for (let i = 0; i < imgCarros.length; i++){
image(imgCarros[i], xCarros[i], yCarros[i], larguraCarro, alturaCarro);
}
}
function movimentaCarro(){
for (let i = 0; i <= 2 ; i++){
xCarros[i] -= veloCarros[i];
}
for (let u = 3; u <= 6; u++){
xCarros[u] += veloCarros[u];
}
}
function voltaInicioCarro(){
for (let i = 0; i <= 2; i++){
if(xCarros[i] < posicaoEsquerda){
xCarros[i] = posicaoDireita;
}
}
for (let u = 3; u <= 6; u++){
if(xCarros[u] > posicaoDireita){
xCarros[u] = posicaoEsquerda;
}
}
}