xxxxxxxxxx
74
//ator
let xAtor = 100;
let yAtor = 366;
//let comprimentoAtor = 30;
//let larguraAtor = 30;
let colisao = false;
let meusPontos = 0;
function mostraAtor(){
image(imagemDoAtor, xAtor, yAtor, 30, 30);
}
function movimentaAtor(){
if (keyIsDown(UP_ARROW)){
yAtor-= 3;
}
if (keyIsDown(DOWN_ARROW)){
if (podeSeMover()){
yAtor+=3;
}
}
if (keyIsDown(RIGHT_ARROW)){
xAtor +=3;
}
if (keyIsDown(LEFT_ARROW)){
xAtor -=3;
}
}
function verificaColisao(){
//collideRectCircle(x1, y1 width1, heigth1, cx, cy, diameter)
for (let i = 0; i < imagemCarros.length; i++){
colisao = collideRectCircle(xCarros[i], yCarros[i], comprimentoCarro, larguraCarro, xAtor, yAtor, 15);
if (colisao){
voltaAtorParaPosicaoinicial();
somDaColisao.play();
if (meusPontos > 0){
meusPontos -=1;
}
}
}
}
function voltaAtorParaPosicaoinicial(){
yAtor = 366;
}
function incluiPontos(){
textAlign(CENTER);
textSize(25);
fill(color(255, 255, 60));
text(meusPontos, width / 5, 27)
}
function meuPonto(){
if (yAtor < 15){
meusPontos +=1;
somDoPonto.play();
voltaAtorParaPosicaoinicial();
}
}
function podeSeMover(){
return yAtor < 366;
}