@Override
  public void endContact(Contact contact) {
    Fixture fixA = contact.getFixtureA();
    Fixture fixB = contact.getFixtureB();

    if ((fixA.isSensor()) && (fixA.getUserData() != null)) {
      B2Controller b2c = (B2Controller) fixA.getUserData();
      b2c.removeBody(fixB.getBody());
    } else if ((fixB.isSensor()) && (fixB.getUserData() != null)) {
      B2Controller b2c = (B2Controller) fixB.getUserData();
      b2c.removeBody(fixA.getBody());
    }
  }
 @Override
 public void beginContact(Contact contact) {
   final Body bodyTab = (Body) mTabSprite[0].getUserData();
   if (contact.getFixtureA().getBody() != bodyTab
       && contact.getFixtureB().getBody() != bodyTab) {
     Vol3Osyougatsu.OGG_A3_A_6_GO.stop();
     Vol3Osyougatsu.OGG_A3_A_6_KACHIN.stop();
     Vol3Osyougatsu.OGG_A3_A_6_GO.play();
     Vol3Osyougatsu.OGG_A3_A_6_KACHIN.play();
     Log.i(TAG, "Va cham rui` ! ---------------");
   }
   Log.i(TAG, "Va cham rui` !");
 }
Beispiel #3
0
  public void beginContact(Contact contact) {
    if (!contact.isTouching()) {
      return;
    }

    Fixture fixture0 = contact.getFixtureA();
    Fixture fixture1 = contact.getFixtureB();

    Item item0 = (Item) fixture0.getUserData();
    Item item1 = (Item) fixture1.getUserData();

    item0.contacted(item1);
  }
  // called when two fixtures no longer collide
  @Override
  public void endContact(Contact c) {
    Fixture fa = c.getFixtureA();
    Fixture fb = c.getFixtureB();

    if (fa == null || fb == null) {
      return;
    }

    if (fa.getUserData() != null && fa.getUserData().equals("foot")) {
      numFootContacts--;
    }
    if (fb.getUserData() != null && fb.getUserData().equals("foot")) {
      numFootContacts--;
    }
  }
  public void addContact(float delta, Contact contact) {
    for (Entity e : entities) {

      if (contact.getFixtureA() == bm.get(e).body.getFixtureList().first()) {
        for (Entity player : players) {
          if (contact.getFixtureB() == sensorm.get(player).sensor) {
            e.add(new CollisionComponent(player.getId(), contact.getWorldManifold()));
            player.add(new CollisionComponent(e.getId(), contact.getWorldManifold()));
            System.out.println("hit a player");

            return;
          }
        }
      }
    }
  }
  public void endContact(float delta, Contact contact) {
    for (Entity e : entities) {

      if (contact.getFixtureA() == bm.get(e).body.getFixtureList().first()) {
        for (Entity player : players) {
          if (bm.has(player) && contact.getFixtureB() == sensorm.get(player).sensor) {

            e.remove(CollisionComponent.class);
            player.remove(CollisionComponent.class);
            System.out.println("No longer a touch");
            return;
          }
        }
      }
    }
  }
  @Override
  public void endContact(Contact contact) {
    if (contact.getFixtureA().getUserData() instanceof ModelData) {
      // if (((ModelData)contact.getFixtureA().getUserData()).getName() {

      // }
    }
  }
  /**
   * Method is called on end of every collision between two Box2D bodies. Behaviour of the end of
   * certain body collisions are defined in this method. Collisions between bodies are defined and
   * accessed by means of bitwise or-ing their category bits.
   */
  @Override
  public void endContact(Contact c) {
    Fixture fa = c.getFixtureA();
    Fixture fb = c.getFixtureB();

    int collisionDefinition = fa.getFilterData().categoryBits | fb.getFilterData().categoryBits;

    switch (collisionDefinition) {
        // foot sensor breaks from floor
      case B2DVars.BIT_PLAYER_FOOT | B2DVars.BIT_BLOCKS:
        numJumps--;
        break;
        // player breaks from end level region
      case B2DVars.BIT_PLAYER | B2DVars.BIT_END:
        break;
    }
  }
  public void beginContact(Contact contact) {
    if (contact.getFixtureA().getBody().getPosition().x * GameMain.PIXELS_TO_METERS
        < GameMain.WIDTH / 2) {
      screen.forceToZero(-1);
    } else {
      screen.forceToZero(1);
    }

    Short a = contact.getFixtureA().getFilterData().categoryBits;
    Short b = contact.getFixtureB().getFilterData().categoryBits;

    if (a.equals(GameMain.METEOR_ENTITY) && b.equals(GameMain.OBSTACLE_ENTITY)
        || b.equals(GameMain.METEOR_ENTITY) && a.equals(GameMain.OBSTACLE_ENTITY)) {

      screen.endGame();
      sound.play();
    }
  }
  @Override
  public void beginContact(Contact contact) {
    // TODO this is ass, research better way of doing this
    Fixture fA = contact.getFixtureA();
    Fixture fB = contact.getFixtureB();
    // all sensors in game are static, so only one fixture can be a sensor
    if (fA.isSensor() && checkSensor(fA, fB)) {
      return;
    } else if (fB.isSensor() && checkSensor(fB, fA)) {
      return;
    }

    final Object o1 = contact.getFixtureA().getBody().getUserData();
    final Object o2 = contact.getFixtureB().getBody().getUserData();

    checkPickup(o1, o2);
    checkRocket(o1, o2);
    // parts are small and dont really intersect, so just getting first one is ok
    final Vector2 position = contact.getWorldManifold().getPoints()[0];
    checkPlayer(o1, o2, position);
  }
  // called when two fixtures start to collide
  @Override
  public void beginContact(Contact c) {
    Fixture fa = c.getFixtureA();
    Fixture fb = c.getFixtureB();

    if (fa == null || fb == null) {
      return;
    }

    if (fa.getUserData() != null && fa.getUserData().equals("foot")) {
      numFootContacts++;
    }
    if (fb.getUserData() != null && fb.getUserData().equals("foot")) {
      numFootContacts++;
    }
    if (fa.getUserData() != null && fa.getUserData().equals("crystal")) {
      bodiesToRemove.add(fa.getBody());
    }
    if (fb.getUserData() != null && fb.getUserData().equals("crystal")) {
      bodiesToRemove.add(fb.getBody());
    }
  }
Beispiel #12
0
  @Override
  public void beginContact(Contact contact) {
    Fixture fa = contact.getFixtureA();
    Fixture fb = contact.getFixtureB();

    // System.out.println("Hello");

    if (fa == null || fb == null) {
      return;
    }

    WorldObject wo1 = (WorldObject) fa.getUserData();
    WorldObject wo2 = (WorldObject) fb.getUserData();

    if (wo1 == null || wo2 == null) {
      return;
    }

    int id1 = wo1.getCId();
    int id2 = wo2.getCId();

    for (ContactListener listener : listeners) {
      // System.out.println("Testing");
      int mask1 = listener.firstMask;
      int mask2 = listener.secondMask;
      /*System.out.format("id1|id2\nmask1|mask2\n%8s|%8s\n%8s|%8s\n",
      Integer.toBinaryString(id1), Integer.toBinaryString(id2),
      Integer.toBinaryString(mask1),
      Integer.toBinaryString(mask2));*/
      if ((id1 & mask1) != 0 && (id2 & mask2) != 0) {
        // System.out.println("Fire normal");
        listener.action.onContact(fa, fb);
      }
      if ((id1 & mask2) != 0 && (id2 & mask1) != 0) {
        // System.out.println("Fire reverse");
        listener.action.onContact(fb, fa);
      }
    }
  }
  public void jump() {

    // get a list of world contacts
    Array<Contact> contacts = world.getContactList();

    // verify if body is grounded or still airborne
    for (Contact contact : contacts) {
      if (contact.getFixtureA().getBody().equals(body)
          || contact.getFixtureB().getBody().equals(body)) {
        currentStates.add(IntelliObjectState.GROUNDED);
        currentStates.remove(IntelliObjectState.AIRBORNE);
        OBJECT_JUMPS_LEFT = OBJECT_JUMPS_AVAILABLE;
      }
    }

    // if body can perform jump, then execute.
    if (OBJECT_JUMPS_LEFT > 0) {
      body.applyLinearImpulse(
          0, OBJECT_JUMP_IMPULSE, body.getPosition().x, body.getPosition().y, true);
      OBJECT_JUMPS_LEFT--;
      currentStates.add(IntelliObjectState.AIRBORNE);
      currentStates.remove(IntelliObjectState.GROUNDED);
    }
  }
  @Override
  public void beginContact(Contact contact) {
    if (contact.getFixtureA().getBody().getUserData() != null
        && contact.getFixtureB().getBody().getUserData() != null) {
      if ((contact.getFixtureA().getBody().getUserData().equals("ball")
              || contact.getFixtureB().getBody().getUserData().equals("ball"))
          && (contact.getFixtureA().getBody().getUserData().equals("leftInRegion")
              || contact.getFixtureB().getBody().getUserData().equals("leftInRegion"))) {

        System.out.println("Score!");
        Play.incrementScore();
      }
    }
  }
 @Override
 public void endContact(Contact contact) {
   final Object o1 = contact.getFixtureA().getBody().getUserData();
   final Object o2 = contact.getFixtureB().getBody().getUserData();
   checkPlayerEnd(o1, o2);
 }
Beispiel #16
0
  @Override
  public void render() {
    // first we update the world. For simplicity
    // we use the delta time provided by the Graphics
    // instance. Normally you'll want to fix the time
    // step.
    long start = TimeUtils.nanoTime();
    world.step(Gdx.graphics.getDeltaTime(), 8, 3);
    float updateTime = (TimeUtils.nanoTime() - start) / 1000000000.0f;

    // next we clear the color buffer and set the camera
    // matrices
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    camera.update();

    // next we render the ground body
    renderBox(groundBody, 50, 1);

    // next we render each box via the SpriteBatch.
    // for this we have to set the projection matrix of the
    // spritebatch to the camera's combined matrix. This will
    // make the spritebatch work in world coordinates
    batch.getProjectionMatrix().set(camera.combined);
    batch.begin();
    for (int i = 0; i < boxes.size(); i++) {
      Body box = boxes.get(i);
      Vector2 position = box.getPosition(); // that's the box's center position
      float angle =
          MathUtils.radiansToDegrees * box.getAngle(); // the rotation angle around the center
      batch.draw(
          textureRegion,
          position.x - 1,
          position.y - 1, // the bottom left corner of the box, unrotated
          1f,
          1f, // the rotation center relative to the bottom left corner of the box
          2,
          2, // the width and height of the box
          1,
          1, // the scale on the x- and y-axis
          angle); // the rotation angle
    }
    batch.end();

    // next we use the debug renderer. Note that we
    // simply apply the camera again and then call
    // the renderer. the camera.apply() call is actually
    // not needed as the opengl matrices are already set
    // by the spritebatch which in turn uses the camera matrices :)
    debugRenderer.render(world, camera.combined);

    // finally we render all contact points
    renderer.setProjectionMatrix(camera.combined);
    renderer.begin(ShapeType.Point);
    renderer.setColor(0, 1, 0, 1);
    for (int i = 0; i < world.getContactCount(); i++) {
      Contact contact = world.getContactList().get(i);
      // we only render the contact if it actually touches
      if (contact.isTouching()) {
        // get the world manifold from which we get the
        // contact points. A manifold can have 0, 1 or 2
        // contact points.
        WorldManifold manifold = contact.getWorldManifold();
        int numContactPoints = manifold.getNumberOfContactPoints();
        for (int j = 0; j < numContactPoints; j++) {
          Vector2 point = manifold.getPoints()[j];
          renderer.point(point.x, point.y, 0);
        }
      }
    }
    renderer.end();

    // finally we render the time it took to update the world
    // for this we have to set the projection matrix again, so
    // we work in pixel coordinates
    batch
        .getProjectionMatrix()
        .setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    batch.begin();
    font.draw(
        batch, "fps: " + Gdx.graphics.getFramesPerSecond() + " update time: " + updateTime, 0, 20);
    batch.end();
  }
  /**
   * Method is called on every collision between two Box2D bodies. Behaviour of certain body
   * collisions are defined in this method. Collisions between bodies are defined and accessed by
   * means of bitwise or-ing their category bits.
   */
  @Override
  public void beginContact(Contact c) {
    Fixture fa = c.getFixtureA();
    Fixture fb = c.getFixtureB();

    int collisionDefinition = fa.getFilterData().categoryBits | fb.getFilterData().categoryBits;

    switch (collisionDefinition) {
        // foot collides with floor
      case B2DVars.BIT_PLAYER_FOOT | B2DVars.BIT_BLOCKS:
        numJumps++;
        break;

        // Player collides with student, deal damage to player or kill enemy
      case B2DVars.BIT_PLAYER | B2DVars.BIT_STUDENT:
        System.out.println("hit!");
        playerStudentCollisionCount++;

        Vector2 playerPosition, playerVelocity, studentPosition;
        Body player, student;

        if (fa.getUserData().equals("player")) {
          player = fa.getBody();
          playerPosition = fa.getBody().getPosition();
          playerVelocity = fa.getBody().getLinearVelocity();
          student = fb.getBody();
          studentPosition = fb.getBody().getPosition();
        } else {
          player = fb.getBody();
          playerPosition = fb.getBody().getPosition();
          playerVelocity = fb.getBody().getLinearVelocity();
          student = fa.getBody();
          studentPosition = fa.getBody().getPosition();
        }

        // Player hits enemy from above, 0.1 offset is to ensure player is significantly above enemy
        if (playerPosition.y - 0.1 > studentPosition.y && playerVelocity.y <= 0) {
          Game.ass.getAudio("kill").play(1.0f);
          bodiesToKill.add(student);
          player.setLinearVelocity(player.getLinearVelocity().x, 2f);
        } else {
          ((Player) player.getUserData()).damagePlayer();
          Game.ass.getAudio("hit").play(1.0f);
          Vector2 point = new Vector2(playerPosition.x, playerPosition.y);

          if (playerPosition.x < studentPosition.x) {
            player.applyLinearImpulse(new Vector2(-30f, 0), point, true);
          } else {
            player.applyLinearImpulse(new Vector2(30f, 0), point, true);
          }
        }
        break;

        // player collides with coin
      case B2DVars.BIT_PLAYER | B2DVars.BIT_COINS:
        if (fa.getUserData().equals("coin")) {
          // delete coin
          bodiesToKill.add(fa.getBody());
          Game.ass.getAudio("coin").play(1.0f);
        } else {
          bodiesToKill.add(fb.getBody());
          Game.ass.getAudio("coin").play(1.0f);
        }
        break;

        // player collides with end of level region
      case B2DVars.BIT_PLAYER | B2DVars.BIT_END:
        if (fa.getUserData().equals("end")) {
          Player playerB = (Player) fb.getBody().getUserData();
          if (playerB.getNumCoins() == playerB.getNumCoinsToCollect()) {
            playerB.setLevelCompleteBool(true);
            break;
          }
          playerB.setLevelCompleteBool(false);
          break;
        } else {
          Player playerA = (Player) fa.getBody().getUserData();
          if (playerA.getNumCoins() == playerA.getNumCoinsToCollect()) {
            playerA.setLevelCompleteBool(true);
            break;
          }
          playerA.setLevelCompleteBool(false);
          break;
        }
    }
  }