I have a bunch of objects that are spawned in a certain location and aren't neccesary linked together in a chain. I was wondering how I would link the certain objects in a chain and if I broke the chain, how it could be repaired by relinking it to the closest unlinked part.
For example
From this: *** ******* To this: ************
This is the code for spawning the enemies.
public void addEnemy() { for (int i = 0; i<numOfEnemies; i++) { typesOfEnemies = Greenfoot.getRandomNumber(3)+1; if (spawnDelay == 50) { if (typesOfEnemies == 1) { eBlueStar[i] = new EnemyBlueStar(); addObject(eBlueStar[i], 110,125); } if (typesOfEnemies == 2) { eYellowTriangle[i] = new EnemyYellowTriangle(); addObject(eYellowTriangle[i], 110,125); } if (typesOfEnemies == 3) { eGreenSquare[i] = new EnemyGreenSquare(); addObject(eGreenSquare[i], 110,125); } spawnDelay = 0; } } }