I'm making a small game in p5.js and when the avatar hits a specific object that object needs to trigger a specific scene. The object in questions are 4 hourglasses contained in an array, how do I "access" the array to implement a different collision detection for each object? I hope I've been clear enough.
class HourGlass {
constructor(x, y) {
this.x = x;
this.y = y;
this.w = 60
this.h = 65
}
body() {
imageMode(CENTER);
for (let i = 0; i < timekNum; i++) {
image(hourglass, this.x+(i*150) , this.y+(sin(frameCount/(i+10))*(i+20)), this.w, this.h)
}
}
checkCollision1(){
if (me2.x + me2.w > this[0].x && me2.x < this[0].x + me2.w && me2.y + me2.h/2 > this[0].y && me2.y < this[0].y + this[0].h){
scene = 5
}
}
here is the link to the "full" game https://editor.p5js.org/larie438/sketches/uufycStNE (it should be run in Chrome, for some reason, it runs like garbage in Safari)
Thanks in advance for the help!