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();
}
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;
}
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();
}
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;
}
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);
}
}
Aggregations