Bullets completely broken
Okay. So i am working on this project. The collisions seemed to be working fine, but instead of shooting bullets freely, it shoots them one at a time. Is there anyway to fix this?
The problem was with your
collisionCheck() methods. You see, this was your
and this was your
Even though I'm not that good at js (I learned it ~2 years ago and never used it since, besides for some simple NodeJS projects), I noticed this: In
drawBullets(), you're looping through the bullets, and then in
collisionCheck() you're looping through the bullets again! Suppose you have n bullets. For each bullet, you do n collision checks. In the end you get n^2 collision checks. Here's how I improved your code:
See the difference? Instead of performing collision checks with every single bullet when a SINGLE bullet is drawn, instead you perform collision checks only with that bullet.
Here's the repl that I created, if you'd like to take a look at the modified code.
Ciao for now! If you have any questions, feel free to respond to this comment.