I'm struggling to understand why the array method 'every' is not functioning properly in my project (working on a roguelike dungeon crawler game).
Here's an example of the array of objects I am working with:
{
x: newrm.x,
y: newrm.y + 10,
w: newrm.w,
h: newrm.h,
centerx: newrm.centerx,
centery: newrm.centery + 10
}
My goal is to test whether every element in this new array passes a specific test (to avoid player collision with walls) using the Every method:
if (newdraw.every(isWithin)) {
ctx2.clearRect(0, 0, width, height);
this.setState({ dungeon: newdraw });
}
function isWithin(obj) {
console.log('this is the obj and this is the player', obj, player);
return obj.x < player.x + player.w && obj.x + obj.w > player.x && obj.y < player.y + player.h && obj.h + obj.y > player.y;
}
It appears that not all elements are being checked, as only two objects are showing up in the console log.
Any assistance would be greatly appreciated.
Thank you.