Search in sources :

Example 6 with Flag

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);
            }
        }
    }
}
Also used : Asteroid(spacesettlers.objects.Asteroid) Vector2D(spacesettlers.utilities.Vector2D) Position(spacesettlers.utilities.Position) AbstractObject(spacesettlers.objects.AbstractObject) Beacon(spacesettlers.objects.Beacon) Flag(spacesettlers.objects.Flag)

Aggregations

Flag (spacesettlers.objects.Flag)6 AbstractObject (spacesettlers.objects.AbstractObject)5 Ship (spacesettlers.objects.Ship)5 Base (spacesettlers.objects.Base)3 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 AbstractAction (spacesettlers.actions.AbstractAction)2 DoNothingAction (spacesettlers.actions.DoNothingAction)2 MoveToObjectAction (spacesettlers.actions.MoveToObjectAction)2 Asteroid (spacesettlers.objects.Asteroid)2 Beacon (spacesettlers.objects.Beacon)2 Position (spacesettlers.utilities.Position)2 Team (spacesettlers.clients.Team)1 TeamClient (spacesettlers.clients.TeamClient)1 Vector2D (spacesettlers.utilities.Vector2D)1