use of spacesettlers.objects.Flag in project spacesettlers by amymcgovern.
the class Toroidal2DPhysics method respawnDeadObjects.
/**
* Respawns any dead objects in new random locations. Ships
* have a delay before they can respawn.
*/
public void respawnDeadObjects(Random random, double asteroidMaxVelocity) {
for (AbstractObject object : allObjects) {
if (!object.isAlive() && object.canRespawn()) {
Position newPosition = null;
// flags should re-spawn at a randomly chosen starting location
if (object instanceof Flag) {
Flag flag = (Flag) object;
newPosition = flag.getNewStartingPosition(random);
// ensure their starting location is free (to handle the thought bug the class
// introduced of putting a ship or a base where the flag should spawn)
newPosition = getRandomFreeLocationInRegion(random, flag.getRadius() * 2, (int) newPosition.getX(), (int) newPosition.getY(), 75);
} else {
// note this is time 2 in order to ensure objects don't spawn touching (and just to get
// them a bit farther apart
newPosition = getRandomFreeLocation(random, object.getRadius() * 2);
}
object.setPosition(newPosition);
object.setAlive(true);
object.setDrawable(true);
// reset the UUID if it is a asteroid or beacon
if (object instanceof Asteroid || object instanceof Beacon) {
object.resetId();
}
// make moveable asteroids move again when they respawn
if (object.isMoveable() && !(object instanceof Flag)) {
Vector2D randomMotion = Vector2D.getRandom(random, asteroidMaxVelocity);
object.getPosition().setTranslationalVelocity(randomMotion);
}
}
}
}
Aggregations