Exemplo n.º 1
1
    public void updatePosition(float dt) {
      if (fixed) {
        netForce.reset(); // Shouldn't accumulate forces if fixed
        return;
      }

      updateAcceleration(dt);
      updateVelocity(dt);

      Point prev = new Point(pos.x, pos.y);
      pos.add(vel.copy().scale(dt, dt));

      ensureInBounds();
    }
Exemplo n.º 2
0
    private Point getOffset(Rect r) {
      Point screenCenter = new Point((bounds.x + bounds.w / 2), (bounds.y + bounds.h / 2));
      Point rectCenter = r.getCenter();

      Point diff = rectCenter.diff(screenCenter).scale(PERCENT_DIST, PERCENT_DIST);
      return diff;
    }
Exemplo n.º 3
0
    private void ensureInBounds() {
      if (bounds == null) {
        bounds = new Rect(0, 0, width, height);
      }

      float xMin = bounds.x + radius;
      float xMax = bounds.w + bounds.x - radius;
      float yMin = bounds.y + radius;
      float yMax = (bounds.h + bounds.y) - radius;
      if (pos.x < xMin) {
        pos.x = xMin;

        vel.x *= COLLISION_SCALE;
      } else if (pos.x > xMax) {
        pos.x = xMax;

        vel.x *= COLLISION_SCALE;
      }

      if (pos.y < yMin) {
        pos.y = yMin;
        vel.y *= COLLISION_SCALE;
      } else if (pos.y > yMax) {
        pos.y = yMax;
        vel.y *= COLLISION_SCALE;
      }

      Float p1 = new Float(pos.x);
      Float p2 = new Float(pos.y);
      Float v1 = new Float(vel.x);
      Float v2 = new Float(vel.y);

      // If anything is NaN -- make new Point and Velocity
      if (p1.isNaN(p1) || p2.isNaN(p2) || v1.isNaN(v1) || v2.isNaN(v2)) {
        pos = new Point(random(width), random(height)); // Place new point randomly
        vel = new Vector(0.0f, 0.0f); // Start it out with no movement
      }
    }