private void applyForces(final double dt) {
   for (final Object object : this.particles.keySet()) {
     final Particle particle = this.particles.get(object);
     final Vector oldSpeed = particle.getSpeed();
     final Vector newSpeed = oldSpeed.add(this.forces.get(object).scale(dt / particle.getMass()));
     particle.setSpeed(newSpeed);
   }
 }
Example #2
0
  /**
   * @see
   *     org.newdawn.slick.particles.ParticleEmitter#updateParticle(org.newdawn.slick.particles.Particle,
   *     int)
   */
  @SuppressWarnings("null")
  @Override
  public void updateParticle(Particle particle, int delta) {
    particleCount++;

    // adjust the particles if required
    particle.x += adjustx;
    particle.y += adjusty;

    particle.adjustVelocity(
        windFactor.getValue(0) * 0.00005f * delta, gravityFactor.getValue(0) * 0.00005f * delta);

    float offset = particle.getLife() / particle.getOriginalLife();
    float inv = 1 - offset;
    float colOffset = 0;
    float colInv = 1;

    Color startColor = null;
    Color endColor = null;
    for (int i = 0; i < colors.size() - 1; i++) {
      ColorRecord rec1 = colors.get(i);
      ColorRecord rec2 = colors.get(i + 1);

      if ((inv >= rec1.pos) && (inv <= rec2.pos)) {
        startColor = rec1.col;
        endColor = rec2.col;

        float step = rec2.pos - rec1.pos;
        colOffset = inv - rec1.pos;
        colOffset /= step;
        colOffset = 1 - colOffset;
        colInv = 1 - colOffset;
      }
    }

    if (startColor != null) {
      float r = (startColor.r * colOffset) + (endColor.r * colInv);
      float g = (startColor.g * colOffset) + (endColor.g * colInv);
      float b = (startColor.b * colOffset) + (endColor.b * colInv);

      float a;
      if (alpha.isActive()) a = alpha.getValue(inv) / 255.0f;
      else
        a = ((startAlpha.getValue(0) / 255.0f) * offset) + ((endAlpha.getValue(0) / 255.0f) * inv);
      particle.setColor(r, g, b, a);
    }

    if (size.isActive()) {
      float s = size.getValue(inv);
      particle.setSize(s);
    } else particle.adjustSize(delta * growthFactor.getValue(0) * 0.001f);

    if (velocity.isActive()) particle.setSpeed(velocity.getValue(inv));

    if (scaleY.isActive()) particle.setScaleY(scaleY.getValue(inv));
  }
 private void slowdownSpeeds(final double dt) {
   for (final Object object : this.particles.keySet()) {
     final Particle particle = this.particles.get(object);
     final Vector oldSpeed = particle.getSpeed();
     final double oldSpeedValue = oldSpeed.getLength();
     final double newSpeedValue = this.slowdownFunction.evaluate(oldSpeedValue, dt);
     final Vector newSpeed = oldSpeed.setLength(newSpeedValue);
     particle.setSpeed(newSpeed);
   }
 }