Пример #1
0
 public void jolt() {
   Random r = new Random();
   Vector v = new Vector(r.nextFloat() - 0.5f, r.nextFloat() - 0.5f, 0);
   v.normalize();
   v.scale(0.1f);
   particle.applyForce(v);
 }
Пример #2
0
  public void explosionAt(float mx, float my, float range, float power) {
    float x = particle.getX();
    float y = particle.getY();

    float dx = x - mx;
    float dy = y - my;

    if (dx == 0) dx += 0.000001f;
    if (dy == 0) dy += 0.000001f;

    float d = dx * dx + dy * dy;

    if (d < range * range) {
      Vector push = new Vector(dx, dy, 0);
      push.normalize();
      push.scale(power * (1 - d / range / range));
      particle.applyForce(push);
    }
  }
Пример #3
0
  public void update(int ms) {

    float x = particle.getX();
    float y = particle.getY();

    Vector f = new Vector(0f, -0.001f, 0f);

    float l = 50, r = 750;
    float t = 550, b = 50;
    if (x < l) f.x += 0.002f;
    else if (x > r) f.x -= 0.002f;
    if (y < b) f.y += 0.002f;
    else if (y > t) f.y -= 0.002f;

    particle.applyForce(f);

    particle.integrate(ms);

    particle.clearForces();
  }