i have and object with X;Y coordinates of a green circle, radius const =5. name "Food". 50 objects with random placement around the canvas.
I have and object with X;Y coordinates of a red circle, radius const =8. name "player".
I have X;Y array of coordinates going x,y 50 times (100 cords), name "allFood". with all of the "food" objects
i need to check for collision between food and player on canvas and add scoreboard. I made a workable piece of code:
for (let i = 0; i < 100; i=i+2){
if ((player.x == allFood[i]) && player.y ==(allFood[i+1])){
scoreboard=scoreboard+1
score.innerHTML = scoreboard
}
}
But it checks only if player centre of circle and food centre of circle are pinpoint accurate on the same pixel, which is very annoying. Could anyone help improve the code so its works when both radiuses collide? i dont know any way except 160 ifs checking each pixel..