-1

This is the code I am using for my collision detection:

for(var k = 0; k < enemies.children.length; k++) { 

    if(bullet.x >= enemies.children[k].x + wingmanWidth || 
       bullet.x + sizeBullet <= enemies.children[k].x - wingmanWidth || 
       bullet.y >= enemies.children[k].y + wingmanHeight || 
       bullet.y + sizeBullet <= enemies.children[k].y) 
{
    //not
}else {
    // collsion detected
}

The collision is detected between a single bullet object and multiple wingman objects in the enemies container. Now I want to detect the collision between multiple bullets in the bullets container and multiple wingman objects in the enemies container.

Infinity
  • 243
  • 1
  • 2
  • 10

1 Answers1

1

Fixed it by adding another for loop as Jozef suggested

for(var k = 0; k < enemies.children.length; k++) { 
  for(var j = 0; j < bulletsContainer.children.length; j++) {       
    if(bulletsContainer.children[j].x >= enemies.children[k].x + wingmanWidth || 
       bulletsContainer.children[j].x + sizeBullet <= enemies.children[k].x - wingmanWidth || 
       bulletsContainer.children[j].y >= enemies.children[k].y + wingmanHeight || 
       bulletsContainer.children[j].y + sizeBullet <= enemies.children[k].y) {

        //not
    } else {
        //yes
  }
}
Jozef Dúc
  • 965
  • 2
  • 18
  • 29
Infinity
  • 243
  • 1
  • 2
  • 10