I have created a 2D array that contains the X and Y coordinates for the spawning method. That works great, however after all levels have been done the terminal pops up with "java.lang.ArrayIndexOutOfBoundsException: 4"
Variables declared:
Spawning method:
I had also tried to make an if statement before the first 'for loop' "if (i <4) else Greenfoot.stop()" but, then it would run into an infinite loop instead of stopping, no idea why.
int level = 0;
int score = 0;
int enemyHP = 0;
int [][] enemyLOC= {{800,800,0,0},{50,800,0,800}};
int i = 0;
int n = 0; public void mmethod()
{
while(getObjects(EnemyShip.class).isEmpty())
{
for (i = 0; i < level; i++)
{
for (n = 0; n < 2; n++)
addObject(new EnemyShip(), (enemyLOC[0][i])-(n*60),(enemyLOC[1][i])-(n*60)); // xRIGHT yTOP
}
}
}
