xxxxxxxxxx
115
//variaveis ator:
let xAtor = 700;
let yAtor = 594;
let velocidadeTomate = 3
let colisao = false;
let meusPontos = 0;
let movimenta = true;
let vidas = 3;
function mostraAtor(){
image(imagemDoAtor, xAtor, yAtor , 40, 40);
}
function ator(){
if(meusPontos <= 9)
{
mostraAtor()
}
if (meusPontos == 9){
velocidadeTomate = 4
}
}
function movimentaAtor(){
if (keyIsDown(UP_ARROW) && movimenta){
yAtor -= velocidadeTomate;
}
if (keyIsDown(DOWN_ARROW) && movimenta){
if (podeSeMover()){
yAtor += velocidadeTomate;
}
}
}
function verificaColisao(){
//collideRectCircle(x1, y1, width1, height1, cx, cy, diameter)
for (let i = 0; i < imagemCarros.length; i++){
colisao = collideRectCircle(xCarro[i], yCarro[i], comprimentoCarro, alturaCarro, (xAtor+15), (yAtor+15), 25)
if (colisao){
voltaAtor();
vidas -= 1;
sonColisao.play();
if(meusPontos > 0){
meusPontos -= 1;
}
}
}
}
function verificaColisaoVolta(){
//collideRectCircle(x1, y1, width1, height1, cx, cy, diameter)
for (let i = 0; i < imagemCarrosVolta.length; i++){
colisao = collideRectCircle(xCarroVolta[i], yCarroVolta[i], comprimentoCarro, alturaCarro, (xAtor+15), (yAtor+15), 25)
if (colisao){
voltaAtor();
vidas -= 1;
sonColisao.play();
if(meusPontos > 0){
meusPontos -= 1;
}
}
}
}
function voltaAtor(){
movimenta = false;
yAtor = 594;
setTimeout (() => {movimenta = true}, 300);
}
function incluiPontos(){
textAlign(CENTER);
textSize(25);
fill(color (255, 240, 60));
text("Pontuação " + meusPontos, width /9, 37);
}
function incluiVidas(){
image(imagemDoAtor, 1215, 10, 32, 32)
textAlign(CENTER)
textSize(25)
fill(255, 240, 60)
text(vidas, 1200, 37)
}
function somaPontos(){
if(yAtor < 37){
meusPontos += 1;
somPontos.play();
voltaAtor();
}
}
function podeSeMover(){
return yAtor < 594;
}
function finalizaJogo(){
if (meusPontos >= 10){
voceVenceu();
somDaTrilha.stop();
citySound.stop();
noLoop(); }
if (vidas <= 0){
vocePerdeu();
somDaTrilha.stop();
citySound.stop();
noLoop();
}
}