Example usage for com.badlogic.gdx.physics.box2d ContactImpulse getNormalImpulses

List of usage examples for com.badlogic.gdx.physics.box2d ContactImpulse getNormalImpulses

Introduction

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

Prototype

public float[] getNormalImpulses() 

Source Link

Usage

From source file:com.strategames.catchdastars.game.CatchDaStars.java

License:Open Source License

private void handleBalloonRockCollision(ContactImpulse impulse, Balloon balloon, GameObject gameObject) {
    if (gameObject instanceof Icecube) {
        if (impulse.getNormalImpulses()[0] > 2) {
            destroyBalloon(balloon);/*  w  ww . ja  v  a 2s  .c  o m*/
        }
    }
}

From source file:com.strategames.engine.gameobject.types.Balloon.java

License:Open Source License

@Override
public void handleCollision(Contact contact, ContactImpulse impulse, GameObject gameObject) {
    float[] impulses = impulse.getNormalImpulses();
    if (impulses[0] > 0.04) {
        //If impulse is greater then maxImpulse we play volume at max (i.e. 1f)
        //otherwise we divide impulse by maxImpulse to make sound softer if balloon
        //hits object softer
        float volume = impulses[0] > maxImpulse ? 1f : (impulses[0] / maxImpulse);
        this.soundBalloonBounce.play(volume);
    }//from   w  w w. j av  a2s .  co m
}

From source file:com.strategames.engine.gameobject.types.Icecube.java

License:Open Source License

@Override
public void handleCollision(Contact contact, ContactImpulse impulse, GameObject gameObject) {
    float maxImpulse = 0.0f;

    float[] impulses = impulse.getNormalImpulses();

    maxImpulse = impulses[0] > maximumImpulse ? maximumImpulse : impulses[0];

    if (maxImpulse > 20) { // prevent counting rocks hitting when they are lying on top of eachother
        rocksHit++;/*from   w w  w  .j  a v a2 s .  co m*/
        rocksHitTotalImpulse += maxImpulse;

        if ((maxImpulse > 50) && (this.amountOfParts > 1)) { // break object

            if (this.breakOfPart == null) {

                Body body = getBody();
                //Get colliding fixture for this object
                Fixture fixture = contact.getFixtureA();
                if (fixture.getBody() != body) {
                    fixture = contact.getFixtureB();
                }

                /**
                 * fixtures get reused and sometimes seem to be available in the wrong object
                 * (fixtures from an old object which has not yet been removed)
                 */
                if (body.getFixtureList().contains(fixture, true)) {
                    Integer userData = (Integer) fixture.getUserData();
                    if (userData != null) {
                        try {
                            this.breakOfPart = this.parts.get(userData.intValue());
                        } catch (IndexOutOfBoundsException e) {
                            Gdx.app.log("Icecube", "handleCollision: array out of bounds: this=" + this
                                    + "fixture=" + fixture);
                        }
                    }
                }
            }
        }
    }
}

From source file:com.tnf.ptm.common.PtmContactListener.java

License:Apache License

private float calcAbsImpulse(ContactImpulse impulse) {
    float absImpulse = 0;
    int pointCount = impulse.getCount();
    float[] normImpulses = impulse.getNormalImpulses();
    for (int i = 0; i < pointCount; i++) {
        float normImpulse = normImpulses[i];
        normImpulse = PtmMath.abs(normImpulse);
        if (absImpulse < normImpulse) {
            absImpulse = normImpulse;/*from   www.  j a v a  2 s.c  o m*/
        }
    }
    return absImpulse;
}

From source file:org.destinationsol.game.SolContactListener.java

License:Apache License

private float calcAbsImpulse(ContactImpulse impulse) {
    float absImpulse = 0;
    int pointCount = impulse.getCount();
    float[] normImpulses = impulse.getNormalImpulses();
    for (int i = 0; i < pointCount; i++) {
        float normImpulse = normImpulses[i];
        normImpulse = SolMath.abs(normImpulse);
        if (absImpulse < normImpulse)
            absImpulse = normImpulse;/*from   w w  w .  j  av a2s . c o m*/
    }
    return absImpulse;
}