So I’m implementing Separating Axis Theorem right now and currently it works perfectly when just looping through two objects, however if I were to add any more objects to my List then the code would break without errors:
public boolean separatingAxisTheorem(){
//this method is being called constantly in my update methods
for(DevEntity e : handler.getDevWorld().getDevM().getDevEntities()){
//here I am looping through a list of the entities in my world
obtainEdges();
if(!e.equals(this)){
Vector2[] axes1 = axis;
Vector2[] axes2 = e.axis;
for(int i = 0; i < axes1.length; i++){
Vector2 axis = axes1[i];
p1 = new Vector2(projectAxis(axis));
p2 = new Vector2(e.projectAxis(axis));
if(!p1.overlap(p2)){
return false;
}
}
for(int i = 0; i < axes2.length; i++){
Vector2 axis = axes2[i];
p3 = new Vector2(projectAxis(axis));
p4 = new Vector2(e.projectAxis(axis));
if(!p3.overlap(p4)){
return false;
}
}
}
}
return true;
}
This is how I add to the list in my World class:
devM = new DevEntityManager(handler, new DevPlayer(handler, (1270/2) -
32, (720/2) - 32));
devM.addDevEntity(new DevSquareEnemy(handler, 200, 400));
//devM.addDevEntity(new DevTriEnemy(handler, 200, 100));
With the second addition commented out my code works fine and my code returns true/false depending on if my player is intersecting my DevSquareEnemy object, however if I remove the comment then my code will only return false, and I think this is because of the way I am adding my objects to the list, I have tried replacing my for loop with an Iterator and while loop but then I started receiving ConcurrentModificationException’s