Closed anaismveras closed 3 years ago
Hey Ana, add a little description of how we solved this problem, and then close the issue. Thanks!
solved the issue by writing logic that the trash or the beachGoers can only be pushed into their arrays only if they show on the canvas in an empty spot
const findEmptySpot = (thing, thingArr) => {
for (let i = 0; i < thingArr.length; i++) {
if (
thing.x < thingArr[i].x + thingArr[i].width &&
thing.x + thing.width > thingArr[i].x &&
thing.y < thingArr[i].y + thingArr[i].height &&
thing.y + thing.height > thingArr[i].y
) {
return false;
}
}
return true;
};
// the if statement below is in my class function to create trash, there is also another one in create beachGoers
if (
findEmptySpot(garbage, trashArray) &&
findEmptySpot(garbage, beachGoerArray)
) {
trashArray.push(garbage);
}
What's the problem you're trying to solve?
so when i play the game, there is trash and there are Beach goers but sometimes the trash goes under the Beach Goer where either I cant see it or I cant get to it to get the point
Post any code you think might be relevant (one fenced block per file)
If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?
no errors
What is your best guess as to the source of the problem?
What things have you already tried to solve the problem?
I tried doing like a hit detection function for both the trash array and the Beach Goers array with for loop but it doesnt work