@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 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); }
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); }
@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` !"); }
// 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 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; } } } } }
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; } } } } }
/** * 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(); } }
// 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()); } }
@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 endContact(Contact contact) { final Object o1 = contact.getFixtureA().getBody().getUserData(); final Object o2 = contact.getFixtureB().getBody().getUserData(); checkPlayerEnd(o1, o2); }
/** * 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; } } }