+ 1
Buggy output after collision
When the enemy bullets hit the ship, the ship damage is meant to increase by 1 and the bullet gets spliced. When hit, the damage glitches out and I can't fix it. I have no idea why because I used this exact technique for the player bullets and the enemy ships and it worked fine. Line 231 - end https://code.sololearn.com/WRNWxkxdCzpg/?ref=app
2 Answers
+ 1
Mirielle thanks. It didn't solve the issue through.
0
Clueless Coder
To solve your damage and buggy output problems, you need to remove the for/loop at line 178 leaving line 179 as is.
Why? Every enemy bullet pushed to the bulletsE array when the condition is met at line 177 will have the same x and y coordinates and of course, the number of enemy bullets pushed depends on the length of the enemies array.
If there are 50 enemy ships, when the condition is met, 50 enemy bullets with the same coordinates will be added to the bulletsE array. So what looks like a single bullet fired from an enemy ship is, in this case, actually 50 enemy bullets. And every one of them is counted as damage when they collide with the player's ship.
https://code.sololearn.com/WD5KoCiyKqUJ/#js
You can control the number of enemy bullets drop by adjusting the number in the conditional at line 177