Search in sources :

Example 6 with Entity

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

the class RenderableComponentComparator method compare.

@Override
public int compare(Entity o1, Entity o2) {
    EntityComponents entity1Components = factory.get(o1);
    EntityComponents entity2Components = factory.get(o2);
    RenderableComponent c1 = entity1Components.renderableComponent;
    RenderableComponent c2 = entity2Components.renderableComponent;
    if (c1.renderable.getLayer() != c2.renderable.getLayer())
        return c1.renderable.getLayer() - c2.renderable.getLayer();
    OwnerComponent ownerComponent1 = entity1Components.ownerComponent;
    OwnerComponent ownerComponent2 = entity2Components.ownerComponent;
    int id1 = o1.getId();
    int id2 = o2.getId();
    if (ownerComponent1 != null) {
        Entity owner = ownerComponent1.getOwner();
        if (owner != null)
            id1 = owner.getId();
    }
    if (ownerComponent2 != null) {
        Entity owner = ownerComponent2.getOwner();
        if (owner != null)
            id2 = owner.getId();
    }
    if (id1 != id2)
        return id1 - id2;
    return c1.renderable.getSubLayer() - c2.renderable.getSubLayer();
}
Also used : Entity(com.artemis.Entity) OwnerComponent(com.gemserk.commons.artemis.components.OwnerComponent) RenderableComponent(com.gemserk.commons.artemis.components.RenderableComponent)

Example 7 with Entity

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

the class EntityStore method get.

public Entity get() {
    Entity e = super.get();
    e.enable();
    return e;
}
Also used : Entity(com.artemis.Entity)

Example 8 with Entity

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

the class PhysicsUtils method releaseContacts.

public static void releaseContacts(Contacts contacts) {
    // removes contact from the other entity
    for (int i = 0; i < contacts.getContactCount(); i++) {
        Contact contact = contacts.getContact(i);
        Fixture myFixture = contact.getMyFixture();
        Fixture otherFixture = contact.getOtherFixture();
        contactsToRemove.add(contact);
        Body otherBody = otherFixture.getBody();
        if (otherBody == null)
            continue;
        Entity otherEntity = (Entity) otherBody.getUserData();
        if (otherEntity == null)
            continue;
        // entitiesInContact.add(otherEntity);
        // removes the contact from the other entity.
        PhysicsComponent otherPhyiscsComponent = Components.getPhysicsComponent(otherEntity);
        otherPhyiscsComponent.getContact().removeContact(otherFixture, myFixture);
    }
    for (int i = 0; i < contactsToRemove.size; i++) {
        Contact contact = contactsToRemove.get(i);
        contacts.removeContact(contact.getMyFixture(), contact.getOtherFixture());
    }
    contactsToRemove.clear();
}
Also used : Entity(com.artemis.Entity) PhysicsComponent(com.gemserk.commons.artemis.components.PhysicsComponent) Fixture(com.badlogic.gdx.physics.box2d.Fixture) Body(com.badlogic.gdx.physics.box2d.Body) Contact(com.gemserk.commons.gdx.box2d.Contacts.Contact)

Example 9 with Entity

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

the class TemplateStoreFactory method createObject.

@Override
public Entity createObject() {
    if (entityStore == null)
        throw new RuntimeException("Can't set null EntityStore to the created entity");
    Entity entity = null;
    if (entityTemplate != null)
        entity = entityFactory.instantiate(entityTemplate);
    else
        entity = entityFactory.instantiate(injector.getInstance(entityTemplateClass));
    StoreComponent storeComponent = StoreComponent.get(entity);
    if (storeComponent == null)
        storeComponent = new StoreComponent(null);
    storeComponent.store = entityStore;
    entity.addComponent(storeComponent);
    return entity;
}
Also used : Entity(com.artemis.Entity) StoreComponent(com.gemserk.commons.artemis.components.StoreComponent)

Example 10 with Entity

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

the class MovementSystem method processEntities.

@Override
protected void processEntities() {
    RandomAccessMap<Entity, EntityComponents> allTheEntityComponents = componentsHolder.entityComponents;
    int entitiesSize = allTheEntityComponents.size();
    float delta = GlobalTime.getDelta();
    for (int entityIndex = 0; entityIndex < entitiesSize; entityIndex++) {
        EntityComponents entityComponents = allTheEntityComponents.get(entityIndex);
        MovementComponent movementComponent = entityComponents.movementComponent;
        Spatial spatial = entityComponents.spatialComponent.getSpatial();
        Vector2 velocity = movementComponent.getVelocity();
        tmpVelocity.set(velocity).mul(delta);
        tmpPosition.set(spatial.getX(), spatial.getY()).add(tmpVelocity);
        float newAngle = spatial.getAngle() + delta * movementComponent.getAngularVelocity();
        spatial.setAngle(newAngle);
        spatial.setPosition(tmpPosition.x, tmpPosition.y);
    }
}
Also used : Entity(com.artemis.Entity) Spatial(com.gemserk.commons.gdx.games.Spatial) Vector2(com.badlogic.gdx.math.Vector2) MovementComponent(com.gemserk.commons.artemis.components.MovementComponent)

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