Search in sources :

Example 1 with SpacewarGraphics

use of spacesettlers.graphics.SpacewarGraphics in project spacesettlers by amymcgovern.

the class RandomTeamClient method getMovementStart.

@Override
public Map<UUID, AbstractAction> getMovementStart(Toroidal2DPhysics space, Set<AbstractActionableObject> actionableObjects) {
    HashMap<UUID, AbstractAction> randomActions = new HashMap<UUID, AbstractAction>();
    for (AbstractObject actionable : actionableObjects) {
        if (actionable instanceof Ship) {
            Ship ship = (Ship) actionable;
            AbstractAction current = ship.getCurrentAction();
            // if we finished, make a new spot in space to aim for
            if (current == null || current.isMovementFinished(space)) {
                Position currentPosition = ship.getPosition();
                Position newGoal = space.getRandomFreeLocationInRegion(random, Ship.SHIP_RADIUS, (int) currentPosition.getX(), (int) currentPosition.getY(), RANDOM_MOVE_RADIUS);
                MoveAction newAction = null;
                newAction = new MoveAction(space, currentPosition, newGoal);
                // System.out.println("Ship is at " + currentPosition + " and goal is " + newGoal);
                SpacewarGraphics graphic = new CircleGraphics(1, getTeamColor(), newGoal);
                graphics.add(graphic);
                // Vector2D shortVec = space.findShortestDistanceVector(currentPosition, newGoal);
                // LineShadow lineShadow = new LineShadow(currentPosition, newGoal, shortVec);
                // newShadows.add(lineShadow);
                randomActions.put(ship.getId(), newAction);
            } else {
                randomActions.put(ship.getId(), ship.getCurrentAction());
            }
        } else {
            // it is a base and random doesn't do anything to bases
            randomActions.put(actionable.getId(), new DoNothingAction());
        }
    }
    return randomActions;
}
Also used : MoveAction(spacesettlers.actions.MoveAction) SpacewarGraphics(spacesettlers.graphics.SpacewarGraphics) HashMap(java.util.HashMap) Position(spacesettlers.utilities.Position) AbstractObject(spacesettlers.objects.AbstractObject) CircleGraphics(spacesettlers.graphics.CircleGraphics) Ship(spacesettlers.objects.Ship) UUID(java.util.UUID) AbstractAction(spacesettlers.actions.AbstractAction) DoNothingAction(spacesettlers.actions.DoNothingAction)

Example 2 with SpacewarGraphics

use of spacesettlers.graphics.SpacewarGraphics in project spacesettlers by amymcgovern.

the class JSpaceSettlersComponent method paintComponent.

/**
 * Draw the space background and all the sub components
 */
protected void paintComponent(final Graphics g) {
    super.paintComponent(g);
    final Graphics2D graphics = (Graphics2D) g;
    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // handle a race condition in the GUI
    if (scaleTransform == null) {
        return;
    }
    graphics.transform(scaleTransform);
    // draw space
    g.setColor(Color.BLACK);
    g.fillRect(0, 0, this.width, this.height);
    // handle an annoying race condition in the GUI
    if (simulator == null) {
        return;
    }
    // draw graphic for all the objects
    Set<AbstractObject> allObjects = new LinkedHashSet<AbstractObject>(simulator.getAllObjects());
    for (AbstractObject object : allObjects) {
        SpacewarGraphics graphic = object.getGraphic();
        if (graphic != null) {
            if (graphic.isDrawable()) {
                drawShadow(graphic, graphics);
            }
        }
    }
    // and draw any team graphics from this round
    for (Team team : simulator.getTeams()) {
        Set<SpacewarGraphics> teamShadows = team.getGraphics();
        if (teamShadows != null) {
            for (SpacewarGraphics graphic : teamShadows) {
                if (graphic.isDrawable()) {
                    drawShadow(graphic, graphics);
                }
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SpacewarGraphics(spacesettlers.graphics.SpacewarGraphics) AbstractObject(spacesettlers.objects.AbstractObject) Team(spacesettlers.clients.Team) Graphics2D(java.awt.Graphics2D)

Aggregations

SpacewarGraphics (spacesettlers.graphics.SpacewarGraphics)2 AbstractObject (spacesettlers.objects.AbstractObject)2 Graphics2D (java.awt.Graphics2D)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 UUID (java.util.UUID)1 AbstractAction (spacesettlers.actions.AbstractAction)1 DoNothingAction (spacesettlers.actions.DoNothingAction)1 MoveAction (spacesettlers.actions.MoveAction)1 Team (spacesettlers.clients.Team)1 CircleGraphics (spacesettlers.graphics.CircleGraphics)1 Ship (spacesettlers.objects.Ship)1 Position (spacesettlers.utilities.Position)1