List of usage examples for com.badlogic.gdx.physics.box2d Fixture getBody
public Body getBody()
From source file:be.ac.ucl.lfsab1509.bouboule.game.gameManager.EndGameListener.java
License:Open Source License
@Override public void endContact(final Contact contact) { Fixture fixture1 = contact.getFixtureA(); Fixture fixture2 = contact.getFixtureB(); /* With nightly 20130729, endContact is called when bodies are destroyed * http://code.google.com/p/libgdx/issues/detail?id=1515 * https://github.com/libgdx/libgdx/commit/5bf1e73 *//*from w w w.j a v a2s . co m*/ if (fixture1 == null || fixture2 == null) { Gdx.app.log("KILL", "endContact but no fixture: skip"); return; } short entity1 = ((Entity) fixture1.getBody().getUserData()).getEntity(); short entity2 = ((Entity) fixture2.getBody().getUserData()).getEntity(); if (entity1 == Entity.SCENERY | entity2 == Entity.SCENERY) { if (entity1 == Entity.PLAYER | entity2 == Entity.PLAYER) { if (isAlivePlayer > 1) { //DO NOTHING =) isAlivePlayer--; // Gdx.app.log("Alive", "End Contact = "+isAlivePlayer); //DO NOTHING =) } else if (GlobalSettings.GAME_EXIT == GameExitStatus.NONE) { // we can loose and win the game at the same time!! looseGame(); //Gdx.app.exit(); } } else if (entity1 == Entity.MONSTER | entity2 == Entity.MONSTER) { if (isAliveMonster > 1) { /// Gdx.app.log("Alive", "MONSTER is alive " + (isAliveMonster-1)); //DO NOTHING isAliveMonster--; } else if (GlobalSettings.GAME_EXIT == GameExitStatus.NONE) { // we can loose and win the game at the same time!! winGame(); } } } }
From source file:com.agateau.pixelwheels.bonus.Bullet.java
License:Open Source License
@Override public void preSolve(Contact contact, Fixture otherFixture, Manifold oldManifold) { if (isFinished()) { return;/*from w ww . j av a 2 s . c o m*/ } Object other = otherFixture.getBody().getUserData(); if (other == mShooter) { contact.setEnabled(false); return; } explode(); if (other instanceof Racer) { ((Racer) other).spin(); } else if (other instanceof Explosable) { ((Explosable) other).explode(); } }
From source file:com.agateau.pixelwheels.bonus.Mine.java
License:Open Source License
@Override public void beginContact(Contact contact, Fixture otherFixture) { Object other = otherFixture.getBody().getUserData(); if (!(other instanceof Racer)) { return;/*from w ww . j a v a 2s.c o m*/ } if (mJoint != null && other == mOwner) { return; } explode(); ((Racer) other).spin(); }
From source file:com.agateau.pixelwheels.bonus.Missile.java
License:Open Source License
@Override public void preSolve(Contact contact, Fixture otherFixture, Manifold oldManifold) { if (isFinished()) { return;//from w w w . j a va 2 s . co m } if (mStatus == Status.WAITING) { contact.setEnabled(false); return; } Object other = otherFixture.getBody().getUserData(); if (other == mShooter) { contact.setEnabled(false); return; } explode(); if (other instanceof Racer) { ((Racer) other).spin(); } else if (other instanceof Explosable) { ((Explosable) other).explode(); } }
From source file:com.agateau.pixelwheels.racer.BonusSpotHitComponent.java
License:Open Source License
@Override public void beginContact(Contact contact, Fixture otherFixture) { Object other = otherFixture.getBody().getUserData(); if (other instanceof BonusSpot) { BonusSpot spot = (BonusSpot) other; spot.pickBonus();//from ww w.j a v a2 s . com if (mRacer.getBonus() == null) { // Do not call selectBonus() from here: it would make it harder for bonus code to // create Box2D bodies: since we are in the collision handling code, the physic // engine is locked so they would have to delay such creations. mMustSelectBonus = true; } } }
From source file:com.agateau.pixelwheels.racer.Racer.java
License:Open Source License
@Override public void preSolve(Contact contact, Fixture otherFixture, Manifold oldManifold) { Object other = otherFixture.getBody().getUserData(); mAudioComponent.onCollision();//from w w w. jav a 2 s . c o m if (other instanceof Racer) { contact.setEnabled(false); applySimplifiedRacerCollision((Racer) other); } for (Collidable collidable : mCollidableComponents) { collidable.preSolve(contact, otherFixture, oldManifold); } }
From source file:com.agateau.pixelwheels.utils.ClosestBodyFinder.java
License:Open Source License
@Override public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) { if (mFraction < fraction) { // Too far, no need to go further return mFraction; }// ww w . j av a 2 s . co m Body body = fixture.getBody(); if (mBodyFilter != null && !mBodyFilter.acceptBody(body)) { return -1; } mFraction = fraction; mBody = body; return fraction; }
From source file:com.badlogic.gdx.ai.tests.steer.box2d.Box2dFieldOfViewProximity.java
License:Apache License
@SuppressWarnings("unchecked") protected Steerable<Vector2> getSteerable(Fixture fixture) { return (Steerable<Vector2>) fixture.getBody().getUserData(); }
From source file:com.dongbat.game.system.Box2dSystem.java
private void setContactListener() { physicWorld.setContactListener(new ContactListener() { @Override/* w ww.j av a 2 s. c o m*/ public void beginContact(Contact contact) { Fixture fixtureA = contact.getFixtureA(); Fixture fixtureB = contact.getFixtureB(); UUID userDataA = (UUID) fixtureA.getBody().getUserData(); UUID userDataB = (UUID) fixtureB.getBody().getUserData(); addCollidedEntity(userDataA, userDataB); } @Override public void endContact(Contact contact) { Fixture fixtureA = contact.getFixtureA(); Fixture fixtureB = contact.getFixtureB(); UUID userDataA = (UUID) fixtureA.getBody().getUserData(); UUID userDataB = (UUID) fixtureB.getBody().getUserData(); removeCollidedEntity(userDataA, userDataB); } @Override public void preSolve(Contact contact, Manifold oldManifold) { } @Override public void postSolve(Contact contact, ContactImpulse impulse) { } }); }
From source file:com.dongbat.game.util.WorldQueryUtil.java
/** * Find any entity in radius//from ww w . ja v a 2 s . c om * * @param world artemis world * @param location location to find * @param radius radius to find * @return Array of nearest Entity in radius */ public static Array<Entity> findAnyInRadius(final com.artemis.World world, final Vector2 location, final float radius) { final Array<Entity> entities = new Array<Entity>(); QueryCallback callback = new QueryCallback() { @Override public boolean reportFixture(Fixture fixture) { Body body = fixture.getBody(); Entity entity = UuidUtil.getEntityByUuid(world, (UUID) body.getUserData()); float distanceSq = new Vector2(body.getPosition()).sub(location).len2(); if (distanceSq <= radius * radius) { entities.add(entity); } return true; } }; Vector2 lowerLeft = new Vector2(location).sub(radius, radius); Vector2 upperRight = new Vector2(location).add(radius, radius); PhysicsUtil.getPhysicsWorld(world).QueryAABB(callback, lowerLeft.x, lowerLeft.y, upperRight.x, upperRight.y); return entities; }