xxxxxxxxxx
105
// CÓDIGOS PARA ATOR
let xAtor = 150;
let yAtor = 369;
let colisao = false;
let meusPontos = 0;
let movimenta = true;
let vidas = 3;
function mostraAtor() {
image(imagemAtor, xAtor, yAtor, 29, 29);
}
function movimentaAtor() {
// TENTAR ADICIONAR MOVIMENTOS LATERAIS?
if (keyIsDown(UP_ARROW) && movimenta) {
yAtor -= 3;
}
if (keyIsDown(DOWN_ARROW) && movimenta) {
if (podeSeMover()) {
yAtor += 3;
}
}
if (keyIsDown(LEFT_ARROW) && movimenta) {
xAtor -= 3;
}
if (keyIsDown(RIGHT_ARROW) && movimenta) {
xAtor += 3;
}
}
function verificaColisao() {
for (i = 0; i < imagemCarros.length; i++) {
colisao = collideRectCircle(
xCarros[i],
yCarros[i],
comprimentoCarro,
alturaCarro,
xAtor + 14,
yAtor + 14,
27);
if (colisao) {
somColisao.play();
voltaAtorParaInicio();
vidas -= 1;
if (pontosMaiorQueZero()) {
meusPontos -= 1;
}
}
}
}
function voltaAtorParaInicio() {
movimenta = false;
yAtor = 369;
setTimeout(() => {
movimenta = true;
}, 500);
}
function incluiPlacar() {
textAlign(CENTER);
textSize(28);
fill(139, 0, 139);
text(meusPontos, width / 5, 28);
}
function incluiVidas() {
image(imagemAtor, 355, 6, 25, 25);
textAlign(CENTER);
textSize(28);
fill(139, 0, 139);
text(vidas, 400, 27);
}
function marcarPonto() {
if (yAtor < 15) {
meusPontos += 1;
somPonto.play();
voltaAtorParaInicio();
aumentarVelocidade(); // CRIOU UM BUG!!
}
}
function pontosMaiorQueZero() {
return meusPontos > 0;
}
function podeSeMover() {
return yAtor < 369;
}
function finalizaJogo() {
if (meusPontos >= 10) {
voceVenceu();
somTrilha.stop();
noLoop();
}
if (vidas <= 0) {
vocePerdeu();
somTrilha.stop();
noLoop();
}
}