Esempio n. 1
0
  /**
   * Updates the effect.
   *
   * @param g The Graphics component the particles are being drawn with.
   * @return the new screenX and screenY shift values
   */
  public static int[] update() {
    double screenXShift = currentLevel.getScreenXShift();
    double screenYShift = currentLevel.getScreenYShift();
    long elapsedTime = elapsedTime();
    screenXShift +=
        (shakeValues[0]
            * Math.sin(elapsedTime / shakeValues[1])
            * Math.exp(shakeValues[2] * elapsedTime));
    screenYShift +=
        (shakeValues[3]
            * Math.sin(elapsedTime / shakeValues[4])
            * Math.exp(shakeValues[5] * elapsedTime));

    for (int i = 0; i < particles.size(); i++) {
      Particle p = particles.get(i);

      for (Body bod : currentLevel.getBodies()) {
        if (bod.intersects(p)
            || bod.getCenter().distanceSquared(p.getCenter())
                    <= (bod.getRadius() * .5) * (bod.getRadius() * .5)
                && i != 0) {
          particles.remove(i);
          i--;
        }
      }
      for (Blockage blockage : currentLevel.getBlockages()) {
        if (blockage.intersects(p.getCenter()) && i != 0) {
          particles.remove(i);
          i--;
        }
      }
      for (GoalPost gp : currentLevel.getGoalPosts()) {
        if (p.intersects(gp) && i != 0) {
          particles.remove(i);
          i--;
        }
      }
      p.setVelocity(p.getVelocity().multiply(0.99));
      p.move();
    }
    xShift = (int) screenXShift;
    yShift = (int) screenYShift;
    return new int[] {xShift, yShift};
  }