Java Code Examples for com.badlogic.gdx.physics.box2d.ContactImpulse

The following are top voted examples for showing how to use com.badlogic.gdx.physics.box2d.ContactImpulse. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: CodeBase   File: ImpactSoundListener.java   View source code 6 votes vote down vote up
private Sound play(PhysixBodyComponent component, ContactImpulse impulse, Sound ignore) {
    if (component != null) {
        ImpactSoundComponent isc = ComponentMappers.impactSound.get(component.getEntity());
        if (isc != null && isc.sound != ignore && isc.lastPlayed.get() > isc.minDelay) {
            float impulseStrength = Math.abs(impulse.getNormalImpulses()[0]);
            if (impulseStrength > isc.minImpulseStrength) {
                float speed = component.getLinearVelocity().len();
                if (speed > isc.minSpeed) {
                    isc.lastPlayed.reset();
                    SoundEmitter.playGlobal(isc.sound, false, component.getX(), component.getY(), 0);
                    return isc.sound;
                }
            }
        }
    }
    return null;
}
 
Example 2
Project: flixel-gdx-box2d   File: TestBreakable.java   View source code 6 votes vote down vote up
@Override
public void onContact(B2FlxShape sprite1, B2FlxShape sprite2, Contact contact, Manifold oldManifold, ContactImpulse impulse)
{
	if(_broke)
	{
		// The body already broke.
		return;
	}
	
	// Should the body break?
	int count = contact.getWorldManifold().getNumberOfContactPoints();
	
	float maxImpulse = 0.0f;
	for(int i = 0; i < count; i++)
	{
		maxImpulse = B2FlxMath.max(maxImpulse, impulse.getNormalImpulses()[i]);
	}
	
	if(maxImpulse > 40.0f)
	{
		_break = true;
	}
}
 
Example 3
Project: angr   File: ModelContactListener.java   View source code 6 votes vote down vote up
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
    if(impulse.getNormalImpulses()[0] > 0.01)
    {
        /* If body A was hit */
        if(contact.getFixtureA() != null)
        {
            if (Actor.class.isInstance(contact.getFixtureA().getBody().getUserData())) {
                Actor a = (Actor) contact.getFixtureA().getBody().getUserData();
                evalDamage(a, impulse);

            }
        }

        /* If body B was hit */
        if(contact.getFixtureB() != null)
        {
            if (Actor.class.isInstance(contact.getFixtureB().getBody().getUserData())) {
                Actor b = (Actor) contact.getFixtureB().getBody().getUserData();
                evalDamage(b, impulse);
            }
        }
    }
}
 
Example 4
Project: angr   File: ModelContactListener.java   View source code 6 votes vote down vote up
/**
 * Evaluate damage and score, and check if actor needs to be destroyed
 * @param actor Current actor
 * @param impulse Impulse
 */
private void evalDamage(Actor actor, ContactImpulse impulse) {
    if (Destructible.class.isInstance(actor)) {
        /* Hit and check final health status */
        if (((Destructible)actor).getDatamageModel() == null)
            return;
        ((Destructible)actor).getDatamageModel().hit(impulse.getNormalImpulses()[0]);
        if (((Destructible)actor).getDatamageModel().getHealth() < 0.01f) {

            if (!((Destructible)actor).isDestroyed()) {
                /* Update score counter */
                gameState.addPoints(((Destructible)actor).getDatamageModel().getPoints(),
                        ((Destructible)actor).getDatamageModel().isEnemy());

                /* Destroy actor */
                ((Destructible)actor).setDestroyed();
            }
        }
    }
}
 
Example 5
Project: rebel-invader   File: PhysicsListener.java   View source code 5 votes vote down vote up
/**
 * Called every time step while the fixtures are overlapping
 * Gives you a chance to find out what impulses were caused by the collision response after it has been applied
 *
 * @param contact
 * @param impulse
 */
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
    //Gdx.app.log(this.getClass().getSimpleName(), "postSolve() called");

    Body a = contact.getFixtureA().getBody();
    Body b = contact.getFixtureB().getBody();

    // If a is a player
    if (a.getUserData().getClass() == PlayerSystem.class) {
        // If b is a structure
        if (b.getUserData().getClass() == StructureSystem.class) {
            a.setUserData(BodyComponent.PLAYER_STRUCTURE_COLLISION);
        }
        // If b is an enemy
        if (b.getUserData().getClass() == EnemySystem.class) {
            a.setUserData(BodyComponent.PLAYER_ENEMY_COLLISION);
        }
    }

    // If b is a player
    if (b.getUserData().getClass() == PlayerSystem.class) {
        // If a is a structure
        if (a.getUserData().getClass() == StructureSystem.class) {
            b.setUserData(BodyComponent.PLAYER_STRUCTURE_COLLISION);
        }
        // If a is an enemy
        if (a.getUserData().getClass() == EnemySystem.class) {
            b.setUserData(BodyComponent.PLAYER_ENEMY_COLLISION);
        }
    }
}
 
Example 6
Project: libgdxjam   File: CollisionHandler.java   View source code 5 votes vote down vote up
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
	Fixture fixtureA = contact.getFixtureA();
	Fixture fixtureB = contact.getFixtureB();
	
	ContactListener listener = get(
		fixtureA.getFilterData().categoryBits,
		fixtureB.getFilterData().categoryBits
	);
	
	if (listener != null) {
		listener.postSolve(contact, impulse);
	}
}
 
Example 7
Project: ZombieCopter   File: PhysicsSystem.java   View source code 5 votes vote down vote up
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
    Body bodyA = contact.getFixtureA().getBody(), bodyB = contact.getFixtureB().getBody();
    PhysicsComponent physA = (PhysicsComponent)bodyA.getUserData(), 
                     physB = (PhysicsComponent)bodyB.getUserData();
    if (physA == null || physB == null) return;
    physA.addCollisionNormal(impulse.getNormalImpulses()[0]);
    physB.addCollisionNormal(impulse.getNormalImpulses()[0]);
}
 
Example 8
Project: sioncore   File: CollisionHandler.java   View source code 5 votes vote down vote up
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
	Fixture fixtureA = contact.getFixtureA();
	Fixture fixtureB = contact.getFixtureB();
	
	ContactListener listener = getListener(fixtureA.getFilterData().categoryBits,
										   fixtureB.getFilterData().categoryBits);
	
	if (listener != null) {
		listener.postSolve(contact, impulse);
	}
}
 
Example 9
Project: CodeBase   File: PhysixComponentAwareContactListener.java   View source code 5 votes vote down vote up
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
    if (contact.getFixtureA() != null && contact.getFixtureB() != null) {
        for (ComponentContactListener listener : listenerMap.values()) {
            listener.postSolve(contact, impulse);
        }
    }
}
 
Example 10
Project: flixel-gdx-box2d   File: TestCollisionDetection.java   View source code 5 votes vote down vote up
@Override
public void onContact(B2FlxShape sprite1, B2FlxShape sprite2, Contact contact, Manifold oldManifold, ContactImpulse impulse)
{
	_ghost2.removeOverlap();
	if(!_ghost2.gotOverlaps())
		_ghost2.setAlpha(1f);
}
 
Example 11
Project: flixel-gdx-box2d   File: B2FlxContactListener.java   View source code 5 votes vote down vote up
/**
 * Internal: This lets you inspect a contact after the solver is finished. This is useful for inspecting impulses. Note: the contact
 * manifold does not include time of impact impulses, which can be arbitrarily large if the sub-step is small. Hence the
 * impulse is provided explicitly in a separate data structure. Note: this is only called for contacts that are touching,
 * solid, and awake.
 */
@Override
public void postSolve(Contact contact, ContactImpulse impulse)
{
	if(_event == null)
		return;
	_event.oldManifold = null;
	_event.impulse = impulse;
	dispatch(contact, B2FlxContactEvent.POST_SOLVE);
}
 
Example 12
Project: DreamsLibGdx   File: WorldController.java   View source code 5 votes vote down vote up
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
    AbstractWorldManager managerA=getManager(((Box2DPhysicsObject) contact.getFixtureA().getUserData()).getGrupo());
    AbstractWorldManager managerB=getManager(((Box2DPhysicsObject) contact.getFixtureB().getUserData()).getGrupo());

    if(managerA!=null) managerA.handlePostSolve(contact, impulse);
    if(managerB!=null) managerB.handlePostSolve(contact, impulse);

}
 
Example 13
Project: homescreenarcade   File: Field.java   View source code 4 votes vote down vote up
@Override public void postSolve(Contact arg0, ContactImpulse arg1) {
    // Not used.
}
 
Example 14
Project: feup-lpoo-armadillo   File: WorldContactListener.java   View source code 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
}
 
Example 15
Project: water2d-libgdx   File: MyContactListener.java   View source code 4 votes vote down vote up
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
	// TODO Auto-generated method stub
	
}
 
Example 16
Project: libGdx-xiyou   File: Box2DContactListener.java   View source code 4 votes vote down vote up
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
}
 
Example 17
Project: JavityEngine   File: JComponent.java   View source code 4 votes vote down vote up
@Override
public void onCollisionStay(Contact contact, ContactImpulse impulse) {
}
 
Example 18
Project: Undertailor   File: CollisionHandler.java   View source code 4 votes vote down vote up
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {}
 
Example 19
Project: M-M   File: ContactService.java   View source code 4 votes vote down vote up
@Override
public void postSolve(final Contact contact, final ContactImpulse impulse) {
}
 
Example 20
Project: advio   File: ContactListener.java   View source code 4 votes vote down vote up
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
}
 
Example 21
Project: libgdxjam   File: ContactAdapter.java   View source code 4 votes vote down vote up
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {}
 
Example 22
Project: libgdxGP   File: ContactMultiListener.java   View source code 4 votes vote down vote up
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
    for (ContactListener contactListener : contactListeners) {
        contactListener.postSolve(contact, impulse);
    }
}
 
Example 23
Project: Pacman_libGdx   File: WorldContactListener.java   View source code 4 votes vote down vote up
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
}
 
Example 24
Project: BlockBunny   File: BBContactListener.java   View source code 4 votes vote down vote up
public void postSolve(Contact c, ContactImpulse ci) {
}
 
Example 25
Project: Dodgy-Dot   File: GameScreen.java   View source code 4 votes vote down vote up
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
	// TODO Auto-generated method stub
}
 
Example 26
Project: Vector-Pinball-Editor   File: Field.java   View source code 4 votes vote down vote up
@Override public void postSolve(Contact arg0, ContactImpulse arg1) {
    // Not used.
}
 
Example 27
Project: KillTheNerd   File: MyContactListener.java   View source code 4 votes vote down vote up
@Override
public void postSolve(final Contact contact, final ContactImpulse impulse) {
	//
}
 
Example 28
Project: Pong-Tutorial   File: Ball.java   View source code 4 votes vote down vote up
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
	// TODO Auto-generated method stub
	
}
 
Example 29
Project: Pong-Tutorial   File: Bounds.java   View source code 4 votes vote down vote up
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
	// TODO Auto-generated method stub
	
}
 
Example 30
Project: Pong-Tutorial   File: Player.java   View source code 4 votes vote down vote up
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
	// TODO Auto-generated method stub
	
}
 
Example 31
Project: GDXJam   File: GameContactListener.java   View source code 4 votes vote down vote up
@Override
public void postSolve (Contact contact, ContactImpulse impulse) {
	// TODO Auto-generated method stub

}
 
Example 32
Project: tilt-game-android   File: ContactListenerAdapter.java   View source code 4 votes vote down vote up
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
}
 
Example 33
Project: Bomberman_libGdx   File: B2DWorldContactListener.java   View source code 4 votes vote down vote up
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
}
 
Example 34
Project: practicos   File: AdministradorColisiones.java   View source code 4 votes vote down vote up
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
	// TODO Auto-generated method stub

}
 
Example 35
Project: CodeBase   File: ImpactSoundListener.java   View source code 4 votes vote down vote up
@Override
public void postSolve(PhysixContact contact, ContactImpulse impulse) {
    Sound ignore = play(contact.getMyComponent(), impulse, null);
    play(contact.getOtherComponent(), impulse, ignore);
}
 
Example 36
Project: CodeBase   File: PhysixContactAdapter.java   View source code 4 votes vote down vote up
public void postSolve(PhysixContact contact, ContactImpulse impulse) {
}
 
Example 37
Project: CodeBase   File: PhysixComponentAwareContactListener.java   View source code 4 votes vote down vote up
public void postSolve(Contact contact, ContactImpulse impulse) {
    testAndRun(contact, (PhysixContact physixContact) -> postSolve(physixContact, impulse));
}
 
Example 38
Project: CodeBase   File: PhysixComponentAwareContactListener.java   View source code 4 votes vote down vote up
public void postSolve(PhysixContact contact, ContactImpulse impulse) {
    listeners.forEach((PhysixContactListener listener) -> listener.postSolve(contact, impulse));
}
 
Example 39
Project: Little-Nibolas   File: Lanza.java   View source code 4 votes vote down vote up
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
}
 
Example 40
Project: Little-Nibolas   File: Soldado.java   View source code 4 votes vote down vote up
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
}