I'll link my code here. I don't understand why it's giving me this error from time to time while i shoot at enemies. The code uses the p5.js library.
Any help would be appreciated!
function draw(){
background(160);
for(var i in enemies){
enemies[i].show();
enemies[i].move();
for(var j in bullets){
if(enemies[i].isHit(bullets[j])){
bullets.splice(j,1);
enemies.splice(i,1);
}
}
}
for(var i in bullets){
bullets[i].show();
bullets[i].move();
}
pg.show();
}
Here is the function that gets updated every frame, and there's the enemy isHit function (placed in the constructor of Enemy)
this.isHit=function(a){
d=dist(this.x,this.y,a.x,a.y);
if(d<12.5){
return true;
}
else {
return false;
}
}
If you need anything else, i'm here at your disposal!