use of spacesettlers.actions.RawAction in project spacesettlers by amymcgovern.
the class HumanTeamClient method getMovementStart.
/**
* Look at the last key pressed by the human and do its movement
*/
@Override
public Map<UUID, AbstractAction> getMovementStart(Toroidal2DPhysics space, Set<AbstractActionableObject> actionableObjects) {
HashMap<UUID, AbstractAction> actions = new HashMap<UUID, AbstractAction>();
for (AbstractObject actionable : actionableObjects) {
if (actionable instanceof Ship) {
// get the current position
Ship ship = (Ship) actionable;
Position myPosition = ship.getPosition();
Vector2D currentVelocity = myPosition.getTranslationalVelocity();
RawAction action = null;
double angularVel = myPosition.getAngularVelocity();
// if the key was up or down, accelerate along the current line
if (lastKeyPressed == HumanKeyPressed.UP) {
Vector2D newVel = new Vector2D(HUMAN_ACCEL * Math.cos(myPosition.getOrientation()), HUMAN_ACCEL * Math.sin(myPosition.getOrientation()));
newVel.add(currentVelocity);
action = new RawAction(newVel, 0);
} else if (lastKeyPressed == HumanKeyPressed.DOWN) {
Vector2D newVel = new Vector2D(-HUMAN_ACCEL * Math.cos(myPosition.getOrientation()), -HUMAN_ACCEL * Math.sin(myPosition.getOrientation()));
newVel.add(currentVelocity);
action = new RawAction(newVel, 0);
}
// if the key was right or left, turn
if (lastKeyPressed == HumanKeyPressed.RIGHT) {
action = new RawAction(0, HUMAN_TURN_ACCEL);
} else if (lastKeyPressed == HumanKeyPressed.LEFT) {
action = new RawAction(0, -HUMAN_TURN_ACCEL);
}
// was the mouse clicked?
if (lastMouseClick != null) {
if (mouseClickMove == null || mouseClickMove.isMovementFinished(space) || space.findShortestDistance(lastMouseClick, myPosition) > CLICK_DISTANCE) {
mouseClickMove = new MoveAction(space, myPosition, lastMouseClick);
graphicsToAdd.add(new StarGraphics(3, super.teamColor, lastMouseClick));
LineGraphics line = new LineGraphics(myPosition, lastMouseClick, space.findShortestDistanceVector(myPosition, lastMouseClick));
line.setLineColor(super.teamColor);
graphicsToAdd.add(line);
}
actions.put(actionable.getId(), mouseClickMove);
} else {
actions.put(actionable.getId(), action);
}
} else {
// can't really control anything but the ship
actions.put(actionable.getId(), new DoNothingAction());
}
}
return actions;
}
Aggregations