Olá pessoal, poderiam me tirar uma dúvida? Por algum motivo, a minha vaquinha não está colidindo com os 5 primeiros carros, apenas o ultimo. Alguem saberia como arrumar? Link do Jogo : https://editor.p5js.org/moraes1606/full/tqy0K-WEB
Código dos carros:
//Variable Cars
let xCars = [500, 500, 500, 500, 500, 500]
let yCars = [40, 100, 150, 211, 264, 317]
let speedCars = [2.4, 2.8, 3.2, 5, 3.3, 2.9]
widthCars = 50
heightCars = 40
function showCar(){
for(let i = 0; i < imageCars.length; i++){
image(imageCars[i], xCars[i], yCars[i], widthCars, heightCars)}
//image(imageCars[1], xCars[1], yCars[1], widthCars, heightCars)
//image(imageCars[2], xCars[2], yCars[2], widthCars, heightCars)
}
function moveCars(){
for( let i = 0; i < imageCars.length; i++){
xCars[i] -= speedCars[i]}
//xCars[1] -= speedCars[1];
//xCars[2] -= speedCars[2];
}
function returnPositionCar(){
for(let i = 0; i < imageCars.length; i++)
if(backToBeginning(xCars[i])){
xCars[i] = 500}
}
function backToBeginning(xCars){
return xCars < -50
}
Códigos da vaquinha:
//Variables Actor
xActor = 100
yActor = 366
// Variables Points
let myPoints = 0
function actor(){
image(cow, xActor, yActor, 30, 30)
}
function moveActor(){
if (keyIsDown(UP_ARROW)){
yActor -= 3}
if (keyIsDown(DOWN_ARROW)){
if(maxLimiteY()){
yActor += 3
}
}
}
function verifyCollide(){
for(let i = 0; i < imageCars.length; i++)
collide = collideRectCircle(xCars[i], yCars[i], widthCars, heightCars, xActor, yActor, 15)
if(collide){
goBackToStartPosition();
collideSong.play()
if(lostPoints()){
myPoints -= 1;
}
}
}
function goBackToStartPosition(){
yActor = 366;
}
function putPoints(){
text(myPoints, width / 5, 28)
textSize(25)
textAlign(CENTER)
fill(138,43,226)
}
function scoredPoints(){
if(yActor < 15){
myPoints +=1;
pointSong.play();
goBackToStartPosition()
}
}
function lostPoints(){
return myPoints > 0;
}
function maxLimiteY(){
return yActor < 365
}