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;
}
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);
}
}
}
}
}
Aggregations