Search in sources :

Example 16 with Vector2D

use of spacesettlers.utilities.Vector2D in project spacesettlers by amymcgovern.

the class TestVector2D method testVectorRejectAlongYLine.

@Test
public void testVectorRejectAlongYLine() {
    Vector2D vector1 = new Vector2D(0, 10);
    Vector2D vector2 = new Vector2D(0, 10);
    Vector2D resultVector = vector1.vectorRejection(vector2);
    assertEquals(resultVector.getXValue(), 0, 0);
    assertEquals(resultVector.getYValue(), 0, 0);
}
Also used : Vector2D(spacesettlers.utilities.Vector2D) Test(org.junit.Test)

Example 17 with Vector2D

use of spacesettlers.utilities.Vector2D in project spacesettlers by amymcgovern.

the class TestVector2D method testVectorRejectAlongXLine.

@Test
public void testVectorRejectAlongXLine() {
    Vector2D vector1 = new Vector2D(10, 0);
    Vector2D vector2 = new Vector2D(10, 0);
    Vector2D resultVector = vector1.vectorRejection(vector2);
    assertEquals(resultVector.getXValue(), 0, 0);
    assertEquals(resultVector.getYValue(), 0, 0);
}
Also used : Vector2D(spacesettlers.utilities.Vector2D) Test(org.junit.Test)

Example 18 with Vector2D

use of spacesettlers.utilities.Vector2D in project spacesettlers by amymcgovern.

the class TestVector2D method testGetMagnitude.

@Test
public void testGetMagnitude() {
    Vector2D vector1 = new Vector2D(3, -3);
    Vector2D vector2 = new Vector2D(4, 4);
    assertEquals(vector1.getMagnitude(), Math.sqrt(18), 0);
    assertEquals(vector2.getMagnitude(), Math.sqrt(32), 0);
}
Also used : Vector2D(spacesettlers.utilities.Vector2D) Test(org.junit.Test)

Example 19 with Vector2D

use of spacesettlers.utilities.Vector2D in project spacesettlers by amymcgovern.

the class TestVector2D method testVectorProjectRejectDiagonal.

@Test
public void testVectorProjectRejectDiagonal() {
    Vector2D vector1 = new Vector2D(10, 10);
    Vector2D vector2 = new Vector2D(0, 10);
    Vector2D resultVector = vector1.vectorProject(vector2);
    assertEquals(resultVector.getXValue(), 0, 0);
    assertEquals(resultVector.getYValue(), 10, 0);
    Vector2D resultVector2 = vector1.vectorRejection(vector2);
    assertEquals(resultVector2.getXValue(), 10, 0);
    assertEquals(resultVector2.getYValue(), 0, 0);
}
Also used : Vector2D(spacesettlers.utilities.Vector2D) Test(org.junit.Test)

Example 20 with Vector2D

use of spacesettlers.utilities.Vector2D 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;
}
Also used : HashMap(java.util.HashMap) Position(spacesettlers.utilities.Position) RawAction(spacesettlers.actions.RawAction) LineGraphics(spacesettlers.graphics.LineGraphics) MoveAction(spacesettlers.actions.MoveAction) Vector2D(spacesettlers.utilities.Vector2D) AbstractObject(spacesettlers.objects.AbstractObject) Ship(spacesettlers.objects.Ship) UUID(java.util.UUID) StarGraphics(spacesettlers.graphics.StarGraphics) AbstractAction(spacesettlers.actions.AbstractAction) DoNothingAction(spacesettlers.actions.DoNothingAction)

Aggregations

Vector2D (spacesettlers.utilities.Vector2D)49 Test (org.junit.Test)33 Position (spacesettlers.utilities.Position)26 Movement (spacesettlers.utilities.Movement)15 Asteroid (spacesettlers.objects.Asteroid)8 Ship (spacesettlers.objects.Ship)8 MoveAction (spacesettlers.actions.MoveAction)4 Before (org.junit.Before)3 AbstractObject (spacesettlers.objects.AbstractObject)3 Toroidal2DPhysics (spacesettlers.simulator.Toroidal2DPhysics)2 HashMap (java.util.HashMap)1 Random (java.util.Random)1 UUID (java.util.UUID)1 AbstractAction (spacesettlers.actions.AbstractAction)1 DoNothingAction (spacesettlers.actions.DoNothingAction)1 RawAction (spacesettlers.actions.RawAction)1 LineGraphics (spacesettlers.graphics.LineGraphics)1 StarGraphics (spacesettlers.graphics.StarGraphics)1 Beacon (spacesettlers.objects.Beacon)1 Flag (spacesettlers.objects.Flag)1