Example usage for com.badlogic.gdx.physics.box2d Contact getFixtureA

List of usage examples for com.badlogic.gdx.physics.box2d Contact getFixtureA

Introduction

In this page you can find the example usage for com.badlogic.gdx.physics.box2d Contact getFixtureA.

Prototype

public Fixture getFixtureA() 

Source Link

Document

Get the first fixture in this contact.

Usage

From source file:be.ac.ucl.lfsab1509.bouboule.game.gameManager.EndGameListener.java

License:Open Source License

@Override
public void beginContact(final Contact contact) {
    short entity1 = ((Entity) contact.getFixtureA().getBody().getUserData()).getEntity();
    short entity2 = ((Entity) contact.getFixtureB().getBody().getUserData()).getEntity();

    // Gdx.app.log("Contact", entity1 + "    "+ entity2);

    if (entity1 == Entity.SCENERY | entity2 == Entity.SCENERY) {

        if (entity1 == Entity.BONUS | entity2 == Entity.BONUS) {

            ((Entity) contact.getFixtureA().getBody().getUserData()).setAlive(true);
            ((Entity) contact.getFixtureB().getBody().getUserData()).setAlive(true);

        } else {//www  . java  2  s  .c  om

            if (entity1 == Entity.PLAYER | entity2 == Entity.PLAYER) {

                isAlivePlayer++;
                // Gdx.app.log("Alive", "Begin Contact = "+isAlivePlayer);

            } else if (entity1 == Entity.MONSTER | entity2 == Entity.MONSTER) {

                isAliveMonster++;
            }

        }

    } else if ((entity1 == Entity.PLAYER && entity2 == Entity.MONSTER)
            | (entity1 == Entity.MONSTER && entity2 == Entity.PLAYER)) {

        // Gdx.app.log("Chocs de Bouboules", "CHOCS || CHOCS");
        GlobalSettings.GAME.hitSound();

    } else if (entity1 == Entity.BONUS) {
        ((Entity) contact.getFixtureA().getBody().getUserData()).attributeBonus(entity2, contact.getFixtureB());

    } else if (entity2 == Entity.BONUS) {
        ((Entity) contact.getFixtureB().getBody().getUserData()).attributeBonus(entity1, contact.getFixtureA());
    }

}

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
     *///w  w  w . ja  v a  2 s. c o  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.GameWorld.java

License:Open Source License

@Override
public void beginContact(Contact contact) {
    Object userA = contact.getFixtureA().getBody().getUserData();
    Object userB = contact.getFixtureB().getBody().getUserData();
    if (userA instanceof Collidable) {
        ((Collidable) userA).beginContact(contact, contact.getFixtureB());
    }/*from  ww  w.j  a  v  a 2s .  co  m*/
    if (userB instanceof Collidable) {
        ((Collidable) userB).beginContact(contact, contact.getFixtureA());
    }
}

From source file:com.agateau.pixelwheels.GameWorld.java

License:Open Source License

@Override
public void endContact(Contact contact) {
    Object userA = contact.getFixtureA().getBody().getUserData();
    Object userB = contact.getFixtureB().getBody().getUserData();
    if (userA instanceof Collidable) {
        ((Collidable) userA).endContact(contact, contact.getFixtureB());
    }/*from   w w  w .jav  a 2  s.  com*/
    if (userB instanceof Collidable) {
        ((Collidable) userB).endContact(contact, contact.getFixtureA());
    }
}

From source file:com.agateau.pixelwheels.GameWorld.java

License:Open Source License

@Override
public void preSolve(Contact contact, Manifold oldManifold) {
    Object userA = contact.getFixtureA().getBody().getUserData();
    Object userB = contact.getFixtureB().getBody().getUserData();
    if (userA instanceof Collidable) {
        ((Collidable) userA).preSolve(contact, contact.getFixtureB(), oldManifold);
    }/*  ww w.  j av  a  2s  .co  m*/
    if (userB instanceof Collidable) {
        ((Collidable) userB).preSolve(contact, contact.getFixtureA(), oldManifold);
    }
}

From source file:com.agateau.pixelwheels.GameWorld.java

License:Open Source License

@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
    Object userA = contact.getFixtureA().getBody().getUserData();
    Object userB = contact.getFixtureB().getBody().getUserData();
    if (userA instanceof Collidable) {
        ((Collidable) userA).postSolve(contact, contact.getFixtureB(), impulse);
    }/*from  w ww .  ja  va 2 s .  c  o m*/
    if (userB instanceof Collidable) {
        ((Collidable) userB).postSolve(contact, contact.getFixtureA(), impulse);
    }
}

From source file:com.arkanoid.game.model.GameField.java

License:Apache License

@Override
public void beginContact(Contact contact) {
    Object bodyA = contact.getFixtureA().getBody().getUserData();
    Object bodyB = contact.getFixtureB().getBody().getUserData();
    if (bodyA != null && bodyB != null) {
        contactMask = 0;//from  w  w w  . jav  a2 s.  c o  m
        if (bodyA.getClass() == Ball.class || bodyB.getClass() == Ball.class) {
            contactMask = contactMask | BALL_CONTACT;
        }
        if (bodyA.getClass() == Vaus.class || bodyB.getClass() == Vaus.class) {
            contactMask = contactMask | VAUS_CONTACT;
        }
        if (bodyA.getClass() == Border.class || bodyB.getClass() == Border.class) {
            contactMask = contactMask | BORDER_CONTACT;
        }
        if (bodyA.getClass() == Brick.class) {
            contactMask = contactMask | BRICK_CONTACT;
            bumpedBrick = (Brick) bodyA;
        } else if (bodyB.getClass() == Brick.class) {
            contactMask = contactMask | BRICK_CONTACT;
            bumpedBrick = (Brick) bodyB;
        }
        processBeginContact();
    }
}

From source file:com.badlogic.gdx.tests.box2d.ConveyorBelt.java

License:Apache License

public void preSolve(Contact contact, Manifold oldManifold) {
    Fixture fixtureA = contact.getFixtureA();
    Fixture fixtureB = contact.getFixtureB();

    if (fixtureA == m_platform || fixtureB == m_platform) {
        contact.setTangentSpeed(5.0f);/* w  ww .ja  va2  s. c  o m*/
    }
}

From source file:com.dgzt.core.EventListener.java

License:Open Source License

/**
 * The Box2D begin contact listener method.
 *///  w w w .j a  v  a2s. c o  m
@Override
public void beginContact(Contact contact) {
    Gdx.app.log(EventListener.class.getName() + ".beginContact", "");

    final Object userDataA = contact.getFixtureA().getUserData();

    if (userDataA instanceof LeftGate) {
        Gdx.app.log(EventListener.class.getName() + ".beginContact", "Opponent goal!!");
        gameControl.opponentGoal();
    }

    if (userDataA instanceof RightGate) {
        Gdx.app.log(EventListener.class.getName() + ".beginContact", "Player goal!!");
        gameControl.playerGoal();
    }
}

From source file:com.dgzt.core.EventListener.java

License:Open Source License

/**
 * The Box2D end contact listener method.
 *///from w w w .  ja  v  a2 s  .co m
@Override
public void endContact(Contact contact) {
    Gdx.app.log(EventListener.class.getName() + ".endContact", "");

    final Object userDataA = contact.getFixtureA().getUserData();

    if (userDataA instanceof Map) {
        final Ball ball = (Ball) contact.getFixtureB().getUserData();
        final LeftGate leftGate = table.getLeftGate();
        final RightGate rightGate = table.getRightGate();

        if ((ball.getBox2DY() < leftGate.getBox2DY()
                || ball.getBox2DY() > leftGate.getBox2DY() + AbstractGate.HEIGHT) // Left gate
                || (ball.getBox2DY() < rightGate.getBox2DY()
                        || ball.getBox2DY() > rightGate.getBox2DY() + AbstractGate.HEIGHT) // Right gate
        ) {
            Gdx.app.log(EventListener.class.getName() + ".endContact", "Ball out the map.");
        }
    }
}