Ejemplo n.º 1
0
  @Override
  public void awake() {
    rand = new Random();

    texture = new Texture("aiplayer.png");
    spriteBatch = new SpriteBatch();
    sprite = new Sprite(texture);
    collider =
        new BoxCollider(
            new Rect(sprite),
            false,
            new ContactListener() {
              @Override
              public void onContactEnter(Collider collider) {
                if (collider.tag.equals("Ball")) {
                  Vector2 ballVelocity = collider.rigidBody.getVelocity();
                  ballVelocity.set(ballVelocity.getX() * translation * 0.2f, -ballVelocity.getY());
                }
              }
            });
    collider.tag = "Platform";

    sprite.translateY(Application.HEIGHT / 2 - sprite.getWidth() / 2 + 40);
    collider.shape.translateY(Application.HEIGHT / 2 - sprite.getWidth() / 2 + 40);
  }
Ejemplo n.º 2
0
  public static void removeOverlappers(ArrayList<Atom> atomList, double minSpace) {
    int size = atomList.size();

    for (int i = 0; i < size; i++) {
      for (int p = 0; p < size; p++) {

        double dist = 1000;
        if (i != p && i < atomList.size() && p < atomList.size()) {
          dist = Collider.getDist(atomList.get(i), atomList.get(p));
        }
        if (dist < minSpace) {
          atomList.remove(i);
          p = size + 1;
        }
      }
    }
  }