xxxxxxxxxx
66
//car positions
let carsizex = 70
let carsizey = 40
let carx = [450, 450, 450]
let cary = [40, 95, 150]
let carspeed = [-5, -10, -3]
let lcarx = [50, 50, 50]
let lcary = [210, 260, 315]
let lcarspeed = [5, 10, 3]
function movecars() {
for(let x = 0; x < carx.length; x += 1){
carx[x] += carspeed[x]
lcarx[x] += lcarspeed[x]
if (caroutofbounds(carx[x])){
carx[x] = 540
}
if (lowercaroutofbounds(lcarx[x])){
lcarx[x] = -40
}
}
}
function caroutofbounds(carx) {
return carx < -50
} //its important that these stay separate, every movement function, array, etc... of both lanes. I haven't found a way to put values of both lanes in the same array and have them move in different directions...
function lowercaroutofbounds(lcarx) {
return lcarx > width + 60
//🥳🥳🥳🥳🥳🥳YEAAA SO GLAD YOU MANAGED TO MAKE THESE TWO WORK TOGETHER!!!!! GREAT WORK SOPHIE!!
}
function carscollide(){
let vehicles = [car1, car2, car3]
//??????????? honestly at this point, i'm just happy i wasn't tortured for three days, this is the programming version of using glue and tape on an electronic
// this is a rather thick line, but its very simple. its essentially just a loop that every repetition adds one to a value (starting from 0), and once the value reaches the number of variables inside a table (indicated by the vehicle (array) and length (lenght of the array)). The second line is just the p5.collide2D command for checking collision. It makes the variable "carcollision" be true or false, equally to the command collideRectCircle. The collideRectCircle command reflects itself to all vehicles within the array, via the loop command, i also passed the variables of the size of the car and of the player.
for (let i = 0; i < vehicles.length; i = i + 1){
carcollision = collideRectCircle(carx[i], cary[i], carsizex, carsizey, playervars[0], playervars[1], playervars[3] / 2)
if (carcollision === true){playervars[0] = width/2; playervars[1] = height - 5
if (pointsabovezero()) {playervars[5] -= 1}
}
}
}
function lowercarscollide(){
let lvehicles = [car4, car5, car6]
for (let x = 0; x < lvehicles.length; x = x + 1){
carcollision = collideRectCircle(lcarx[x], lcary[x], carsizex , carsizey, playervars[0], playervars[1], playervars[3] / 2)
if (carcollision === true){playervars[0] = width/2; playervars[1] = height - 5;
if (pointsabovezero()) {playervars[5] -= 1
}
}
}
}