I have recently rebuilt my game in HTML/CSS/JS from scratch, based on an old question. Everything seems to work fine when there is only one player and one brick present. However, as soon as I introduce multiple bricks, things start to go wrong.
I used an array to store objects and implemented a for-of loop to handle movement within the array. The functionality works by checking if the current element (player) is not the same as the object selected by the loop, and then checks for collisions and logs the results accordingly. Here is the code snippet:
.... // code snippet goes here
.... // CSS code snippet goes here
.... // HTML code snippet goes here
While the code successfully detects collisions with the first brick, it fails to do so with the second brick. This issue seems to stem from the if statement within the move function, but I'm unsure. I have researched extensively, but have not found a solution. Can someone please explain why this behavior is occurring? I prefer to avoid using jQuery, but I am open to using it if necessary.