Search in sources :

Example 11 with Entity

use of com.artemis.Entity in project commons-gdx by gemserk.

the class PhysicsContactListener method beginContact.

@Override
public void beginContact(Contact contact) {
    if (!contact.isTouching())
        return;
    Body bodyA = contact.getFixtureA().getBody();
    Body bodyB = contact.getFixtureB().getBody();
    Entity entityA = (Entity) bodyA.getUserData();
    Entity entityB = (Entity) bodyB.getUserData();
    addBodyToContacts(entityA, contact, true);
    addBodyToContacts(entityB, contact, false);
}
Also used : Entity(com.artemis.Entity) Body(com.badlogic.gdx.physics.box2d.Body)

Example 12 with Entity

use of com.artemis.Entity in project commons-gdx by gemserk.

the class ArtemisOutOfBoundsTest method shouldNotFailWhenAskingForComponentOutsideBounds.

@Test
public void shouldNotFailWhenAskingForComponentOutsideBounds() {
    World world = new World();
    Entity e = world.createEntity();
    e.addComponent(new Component1());
    e.addComponent(new Component2());
    e.addComponent(new Component3());
    e.addComponent(new Component4());
    e.addComponent(new Component5());
    e.addComponent(new Component6());
    // e.addComponent(new Component7());
    e.addComponent(new Component8());
    e.addComponent(new Component9());
    e.addComponent(new Component10());
    e.addComponent(new Component11());
    e.addComponent(new Component12());
    e.addComponent(new Component13());
    e.addComponent(new Component14());
    e.addComponent(new Component15());
    e.addComponent(new Component16());
    e.addComponent(new ComponentOutOfBounds());
    e.refresh();
    e.getComponent(Component1.class);
    e.getComponent(Component2.class);
    e.getComponent(Component3.class);
    e.getComponent(Component4.class);
    e.getComponent(Component5.class);
    e.getComponent(Component6.class);
    e.getComponent(Component7.class);
    e.getComponent(Component8.class);
    e.getComponent(Component9.class);
    e.getComponent(Component10.class);
    e.getComponent(Component11.class);
    e.getComponent(Component12.class);
    e.getComponent(Component13.class);
    e.getComponent(Component14.class);
    e.getComponent(Component15.class);
    e.getComponent(Component16.class);
    // e.getComponent(ComponentOutOfBounds.class);
    ComponentOutOfBounds component = e.getComponent(ComponentOutOfBounds.class);
    assertThat(component, IsNull.notNullValue());
    Component7 component7 = e.getComponent(Component7.class);
    assertThat(component7, IsNull.nullValue());
}
Also used : Entity(com.artemis.Entity) World(com.artemis.World) Test(org.junit.Test)

Example 13 with Entity

use of com.artemis.Entity in project commons-gdx by gemserk.

the class ArtemisOutOfBoundsTest method shouldGetComponent.

@Test
public void shouldGetComponent() {
    World world = new World();
    Entity e = world.createEntity();
    e.addComponent(new Component1());
    e.refresh();
    Component1 component = e.getComponent(Component1.class);
    assertThat(component, IsNull.notNullValue());
}
Also used : Entity(com.artemis.Entity) World(com.artemis.World) Test(org.junit.Test)

Example 14 with Entity

use of com.artemis.Entity in project commons-gdx by gemserk.

the class ContainerSystemTest method shouldRemoveChildrenIfParentRemoved.

@Test
public void shouldRemoveChildrenIfParentRemoved() {
    World world = new World();
    WorldWrapper worldWrapper = new WorldWrapper(world);
    worldWrapper.addUpdateSystem(new ContainerSystem());
    worldWrapper.addUpdateSystem(new OwnerSystem());
    worldWrapper.init();
    Entity e1 = world.createEntity();
    e1.addComponent(new ContainerComponent());
    e1.refresh();
    Entity e2 = world.createEntity();
    e2.addComponent(new OwnerComponent(e1));
    e2.refresh();
    worldWrapper.update(10);
    world.deleteEntity(e1);
    worldWrapper.update(1);
    worldWrapper.update(1);
    Entity e3 = world.getEntity(e2.getId());
    assertThat(e3, IsNull.nullValue());
}
Also used : Entity(com.artemis.Entity) WorldWrapper(com.gemserk.commons.artemis.WorldWrapper) OwnerComponent(com.gemserk.commons.artemis.components.OwnerComponent) ContainerComponent(com.gemserk.commons.artemis.components.ContainerComponent) World(com.artemis.World) Test(org.junit.Test)

Example 15 with Entity

use of com.artemis.Entity in project commons-gdx by gemserk.

the class ContainerSystemTest method shouldBeAddedToParentContainer.

@Test
public void shouldBeAddedToParentContainer() {
    World world = new World();
    WorldWrapper worldWrapper = new WorldWrapper(world);
    worldWrapper.addUpdateSystem(new ContainerSystem());
    worldWrapper.addUpdateSystem(new OwnerSystem());
    worldWrapper.init();
    Entity e1 = world.createEntity();
    e1.addComponent(new ContainerComponent());
    e1.refresh();
    Entity e2 = world.createEntity();
    e2.addComponent(new OwnerComponent(e1));
    e2.refresh();
    worldWrapper.update(10);
    ContainerComponent containerComponent = e1.getComponent(ContainerComponent.class);
    assertThat(containerComponent.getChildren().contains(e2), IsEqual.equalTo(true));
}
Also used : Entity(com.artemis.Entity) WorldWrapper(com.gemserk.commons.artemis.WorldWrapper) OwnerComponent(com.gemserk.commons.artemis.components.OwnerComponent) ContainerComponent(com.gemserk.commons.artemis.components.ContainerComponent) World(com.artemis.World) Test(org.junit.Test)

Aggregations

Entity (com.artemis.Entity)59 World (com.artemis.World)38 Test (org.junit.Test)31 RenderableComponent (com.gemserk.commons.artemis.components.RenderableComponent)16 OwnerComponent (com.gemserk.commons.artemis.components.OwnerComponent)15 WorldWrapper (com.gemserk.commons.artemis.WorldWrapper)8 EntityFactory (com.gemserk.commons.artemis.templates.EntityFactory)6 EntityFactoryImpl (com.gemserk.commons.artemis.templates.EntityFactoryImpl)6 EntityTemplate (com.gemserk.commons.artemis.templates.EntityTemplate)6 Spatial (com.gemserk.commons.gdx.games.Spatial)6 SpatialComponent (com.gemserk.commons.artemis.components.SpatialComponent)5 Body (com.badlogic.gdx.physics.box2d.Body)4 ContainerComponent (com.gemserk.commons.artemis.components.ContainerComponent)4 StoreComponent (com.gemserk.commons.artemis.components.StoreComponent)4 ParametersWrapper (com.gemserk.componentsengine.utils.ParametersWrapper)3 ComponentType (com.artemis.ComponentType)2 PreviousStateSpatialComponent (com.gemserk.commons.artemis.components.PreviousStateSpatialComponent)2 SpriteComponent (com.gemserk.commons.artemis.components.SpriteComponent)2 Script (com.gemserk.commons.artemis.scripts.Script)2 Container (com.gemserk.componentsengine.utils.Container)2