Search in sources :

Example 6 with Contact

use of com.gemserk.commons.gdx.box2d.Contacts.Contact in project commons-gdx by gemserk.

the class ContactsTest method removesSecondContactIfItMatches.

@Test
public void removesSecondContactIfItMatches() {
    final Fixture fixtureC = mockery.mock(Fixture.class);
    mockery.checking(new Expectations() {

        {
            ignoring(fixtureA);
            ignoring(fixtureB);
            ignoring(fixtureC);
        }
    });
    contacts.addContact(fixtureA, fixtureC, new Vector2());
    contacts.addContact(fixtureA, fixtureB, normal);
    assertTrue(contacts.isInContact());
    assertThat(2, IsEqual.equalTo(contacts.getContactCount()));
    contacts.removeContact(fixtureA, fixtureB);
    assertTrue(contacts.isInContact());
    assertThat(1, IsEqual.equalTo(contacts.getContactCount()));
    Contact stillValidContact = contacts.contacts.get(0);
    assertTrue(stillValidContact.inContact);
    assertSame(fixtureA, stillValidContact.myFixture);
    assertSame(fixtureC, stillValidContact.otherFixture);
    Contact removedContact = contacts.contacts.get(1);
    assertFalse(removedContact.inContact);
    assertNull(removedContact.myFixture);
    assertNull(removedContact.otherFixture);
}
Also used : Expectations(org.jmock.Expectations) Vector2(com.badlogic.gdx.math.Vector2) Fixture(com.badlogic.gdx.physics.box2d.Fixture) Contact(com.gemserk.commons.gdx.box2d.Contacts.Contact) Test(org.junit.Test)

Example 7 with Contact

use of com.gemserk.commons.gdx.box2d.Contacts.Contact in project commons-gdx by gemserk.

the class ContactsTest method removesFirstOfTwoContactIfItMatches.

@Test
public void removesFirstOfTwoContactIfItMatches() {
    final Fixture fixtureC = mockery.mock(Fixture.class);
    mockery.checking(new Expectations() {

        {
            ignoring(fixtureA);
            ignoring(fixtureB);
            ignoring(fixtureC);
        }
    });
    contacts.addContact(fixtureA, fixtureB, normal);
    contacts.addContact(fixtureA, fixtureC, new Vector2());
    assertTrue(contacts.isInContact());
    assertThat(2, IsEqual.equalTo(contacts.getContactCount()));
    contacts.removeContact(fixtureA, fixtureB);
    assertTrue(contacts.isInContact());
    assertThat(1, IsEqual.equalTo(contacts.getContactCount()));
    Contact stillValidContact = contacts.contacts.get(0);
    assertTrue(stillValidContact.inContact);
    assertSame(fixtureA, stillValidContact.myFixture);
    assertSame(fixtureC, stillValidContact.otherFixture);
    Contact removedContact = contacts.contacts.get(1);
    assertFalse(removedContact.inContact);
    assertNull(removedContact.myFixture);
    assertNull(removedContact.otherFixture);
}
Also used : Expectations(org.jmock.Expectations) Vector2(com.badlogic.gdx.math.Vector2) Fixture(com.badlogic.gdx.physics.box2d.Fixture) Contact(com.gemserk.commons.gdx.box2d.Contacts.Contact) Test(org.junit.Test)

Aggregations

Contact (com.gemserk.commons.gdx.box2d.Contacts.Contact)7 Expectations (org.jmock.Expectations)6 Test (org.junit.Test)6 Vector2 (com.badlogic.gdx.math.Vector2)3 Fixture (com.badlogic.gdx.physics.box2d.Fixture)3 Entity (com.artemis.Entity)1 Body (com.badlogic.gdx.physics.box2d.Body)1 PhysicsComponent (com.gemserk.commons.artemis.components.PhysicsComponent)1