xxxxxxxxxx
81
//códigos do ator
let yAtor = 370;
let xAtor = 85;
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(LEFT_ARROW)){
if(xAtor > 0){
xAtor -= 3;
}
}
if(keyIsDown(RIGHT_ARROW)){
if(xAtor < 470){
xAtor += 3;
}
}
}
function podeSeMover(){
return yAtor < 370
}
//utilizando a biblioteca p5.collide2d
function verificaColisao(){
for (let i = 0;i < imagemCarros.length; i += 1){
if (i < 3) {
colisao = collideRectCircle(xCarros[i], yCarros[i], comprimentoCarro, alturaCarro, xAtor, yAtor, 10)
} else {
scale(-1,1);
colisao = collideRectCircle(-xCarros[i], yCarros[i], comprimentoCarro, alturaCarro, -xAtor, yAtor, 10)
scale(-1,1)
}
if (colisao){
resetaAtor();
if (pontoPositivo()){
meusPontos -= 1
}
somDaColisao.play();
}
}
}
function pontoPositivo(){
return meusPontos > 0
}
function resetaAtor(){
yAtor = 370;
}
function incluiPontos(){
textAlign(CENTER);
textSize(25)
fill(color(255,240,60))
text(meusPontos, width/5, 25);
}
function marcaPontos(){
if (yAtor<15){
meusPontos += 1;
resetaAtor();
somDoPonto.play()
}
}