示例#1
0
  /**
   * Starts the effect.
   *
   * @param currentLevel the level the effect is taking place on
   */
  public static void start(Level currentLevel) {
    started = true;
    CollisionEffect.currentLevel = currentLevel;
    Point2d shift = currentLevel.getShift();
    Ball ball = currentLevel.getBall();
    Body intersected = currentLevel.getIntersectingBody();
    particles = Particle.generateParticles(ball, intersected);
    shakeValues = new double[6];
    double speed = ball.getVelocity().magnitude();

    if (speed < .25) speed = .25;
    if (speed > 2.5) speed = 2.5;

    double shakeFactor = 3 * speed / currentLevel.getFollowFactor();
    if (currentLevel.getFollowFactor() == 0.0) shakeFactor = .25 * speed;
    // 1st value is multiplicative factor
    int sign1 = -1;
    if (ball.getCenter().x() + shift.x() < 0) {
      sign1 = 1;
    } else if (ball.getCenter().x() + shift.x() > 0) {
      sign1 = CalcHelp.randomSign();
    }
    shakeValues[0] = CalcHelp.randomDouble(35, 40) * shakeFactor * sign1;

    int sign2 = -1;
    if (ball.getCenter().y() + shift.y() < 0) {
      sign2 = 1;
    } else if (ball.getCenter().y() + shift.y() > 0) {
      sign2 = CalcHelp.randomSign();
    }
    shakeValues[3] = CalcHelp.randomDouble(35, 40) * shakeFactor * sign2;

    // 2nd value is sinusoidal factor
    shakeValues[1] = CalcHelp.randomDouble(45, 50);
    shakeValues[4] = CalcHelp.randomDouble(45, 50);

    // 3rd value is exponential factor
    shakeValues[2] = CalcHelp.randomDouble(-.0035, -.0045);
    shakeValues[5] = CalcHelp.randomDouble(-.0035, -.0045);

    startTime = System.currentTimeMillis();
    ball.setLaunched(false);
  }
示例#2
0
 private static long elapsedTime() {
   return System.currentTimeMillis() - startTime;
 }