xxxxxxxxxx
133
let comVida = [30, 30, 30];
let altVida = [30, 30, 30];
//v1
let yViDa = [2, 2, 2];
let xViDa = [0, 25, 50];
//Ator
let yAtor = 367;
let xAtor = [80, 100, 130, 150, 200, 230, 250, 300, 330, 350, 400, 430, 470];
const rxAtor = Math.floor(Math.random() * xAtor.length);
var colisao = false;
var mPontos = 0;
function mostraAtor() {
image(imgDoAtor, xAtor[rxAtor], yAtor, 30, 30);
}
function movimentaAtor() {
if (keyIsDown(UP_ARROW)) {
yAtor -= 2;
}
if (keyIsDown(DOWN_ARROW)) {
if (limitDown()) {
yAtor += 2;
}
}
if (keyIsDown(UP_ARROW)) {
yAtor -= 2;
}
if (keyIsDown(LEFT_ARROW)) {
if (limtLeft()) {
xAtor[rxAtor] -= 2;
}
}
if (keyIsDown(RIGHT_ARROW)) {
if (limtRight()) {
xAtor[rxAtor] += 2;
}
}
}
function verificaColisao() {
//collideRectCircle(x1, y1, width1, height1, cx, cy, diameter)
//Rota A
for (let i = 3; i < imgCarrosa.length; i++) {
colisao = collideRectCircle(
xCarros[i],
yCarros[i],
comCarros,
altCarros,
xAtor[rxAtor],
yAtor,
17
);
if (colisao) {
colidiuA();
}
}
function colidiuA() {
yAtor = 367;
if (pontosMQZero()) {
mPontos -= 5;
}
}
//Rota B
for (let i = 0; i < imgCarrosa.length; i++) {
colisao = collideRectCircle(
xCarrosb[i],
yCarrosb[i],
comCarros,
altCarros,
xAtor[rxAtor],
yAtor,
17
);
if (colisao) {
colidioB();
if (pontosMQZero()) {
mPontos -= 5;
}
}
}
function colidioB() {
yAtor = 367;
}
}
function iPontos() {
textAlign(CENTER);
textSize(25);
fill(color(255, 240, 90));
text(mPontos, width / 3, 27);
}
function maPontos() {
if (yAtor < 15) {
mPontos += 5;
yAtor = 367;
}
}
function pontosMQZero() {
return mPontos > 0;
}
function limitDown() {
return yAtor < 366;
}
function limtLeft() {
return xAtor[rxAtor] > 0;
}
function limtRight() {
return xAtor[rxAtor] < 470;
}
function mostraVida() {
for (let i = 0; i < viDa.length; i = i + 1) {
image(viDa[i], xViDa[i], yViDa[i], comVida[i], altVida[i]);
}
}