Search in sources :

Example 26 with Entity

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

the class OrderedByLayerEntitiesTest method shouldReturnEntitySecondIfGreaterLayer.

@Test
public void shouldReturnEntitySecondIfGreaterLayer() {
    World world = new World();
    Entity e1 = world.createEntity();
    Entity e2 = world.createEntity();
    e1.addComponent(new RenderableComponent(0));
    e2.addComponent(new RenderableComponent(-1));
    orderedByLayerEntities.add(e1);
    orderedByLayerEntities.add(e2);
    assertSame(orderedByLayerEntities.get(0), e2);
    assertSame(orderedByLayerEntities.get(1), e1);
}
Also used : Entity(com.artemis.Entity) RenderableComponent(com.gemserk.commons.artemis.components.RenderableComponent) World(com.artemis.World) Test(org.junit.Test)

Example 27 with Entity

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

the class OrderedByLayerEntitiesTest method bugWhenOrderingSubEntity.

@Test
public void bugWhenOrderingSubEntity() {
    World world = new World();
    Entity e1 = world.createEntity();
    Entity e2 = world.createEntity();
    Entity e3 = world.createEntity();
    e1.addComponent(new RenderableComponent(5));
    e2.addComponent(new RenderableComponent(5));
    e3.addComponent(new RenderableComponent(5, -1));
    e3.addComponent(new OwnerComponent(e2));
    orderedByLayerEntities.add(e1);
    orderedByLayerEntities.add(e2);
    orderedByLayerEntities.add(e3);
    assertSame(orderedByLayerEntities.get(0), e1);
    assertSame(orderedByLayerEntities.get(1), e3);
    assertSame(orderedByLayerEntities.get(2), e2);
}
Also used : Entity(com.artemis.Entity) OwnerComponent(com.gemserk.commons.artemis.components.OwnerComponent) RenderableComponent(com.gemserk.commons.artemis.components.RenderableComponent) World(com.artemis.World) Test(org.junit.Test)

Example 28 with Entity

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

the class EntityBuilder method build.

public Entity build() {
    Entity e = world.createEntity();
    if (tag != null)
        e.setTag(tag);
    for (int i = 0; i < components.size(); i++) e.addComponent(components.get(i));
    e.refresh();
    reset();
    return e;
}
Also used : Entity(com.artemis.Entity)

Example 29 with Entity

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

the class RenderLayerSpriteBatchImpl method render.

@Override
public void render() {
    camera.getFrustum(frustum);
    if (optimizationParameters.updateCamera)
        camera.apply(spriteBatch);
    RandomAccessMap<Entity, EntityComponents> entityComponents = factory.entityComponents;
    if (blending && !spriteBatch.isBlendingEnabled())
        spriteBatch.enableBlending();
    else if (!blending && spriteBatch.isBlendingEnabled())
        spriteBatch.disableBlending();
    if (optimizationParameters.beginBatch)
        spriteBatch.begin();
    for (int i = 0; i < orderedByLayerRenderables.size(); i++) {
        Renderable renderable = orderedByLayerRenderables.get(i);
        if (!renderable.isVisible())
            continue;
        EntityComponents components = entityComponents.get(renderable.getEntity());
        FrustumCullingComponent frustumCullingComponent = components.frustumCullingComponent;
        if (frustumCullingComponent != null) {
            Spatial spatial = components.spatialComponent.getSpatial();
            entityBounds.set(frustumCullingComponent.bounds);
            entityBounds.setX(entityBounds.getX() + spatial.getX());
            entityBounds.setY(entityBounds.getY() + spatial.getY());
            if (!frustum.overlaps(entityBounds))
                continue;
        }
        SpriteComponent spriteComponent = components.spriteComponent;
        if (spriteComponent != null) {
            Sprite sprite = spriteComponent.getSprite();
            sprite.setColor(spriteComponent.getColor());
            sprite.draw(spriteBatch);
        }
        // don't like it will be asking for components all the time.
        TextComponent textComponent = components.textComponent;
        if (textComponent != null) {
            BitmapFont font = textComponent.font;
            if (font.getScaleX() != textComponent.scale) {
                font.setScale(textComponent.scale);
            }
            font.setColor(textComponent.color);
            //
            SpriteBatchUtils.drawMultilineText(//
            spriteBatch, //
            font, textComponent.text, textComponent.x, textComponent.y, textComponent.cx, textComponent.cy);
        }
        ParticleEmitterComponent particleEmitterComponent = components.particleEmitterComponent;
        if (particleEmitterComponent != null) {
            particleEmitterComponent.particleEmitter.draw(spriteBatch);
        }
    }
    if (optimizationParameters.endBatch)
        spriteBatch.end();
}
Also used : TextComponent(com.gemserk.commons.artemis.components.TextComponent) Entity(com.artemis.Entity) Renderable(com.gemserk.commons.artemis.render.Renderable) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) Spatial(com.gemserk.commons.gdx.games.Spatial) SpriteComponent(com.gemserk.commons.artemis.components.SpriteComponent) FrustumCullingComponent(com.gemserk.commons.artemis.components.FrustumCullingComponent) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) ParticleEmitterComponent(com.gemserk.commons.artemis.components.ParticleEmitterComponent)

Example 30 with Entity

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

the class EntityTemplateTest method test.

@Test
public void test() {
    EntityTemplate customShipTemplate = new ShipEntityTemplate() {

        {
            parameters.put("x", 100f);
            parameters.put("y", 200f);
            parameters.put("health", new Container(53f, 250f));
        }
    };
    EntityFactory entityFactory = new EntityFactoryImpl(new World());
    Entity entity = entityFactory.instantiate(customShipTemplate);
    SpatialComponent spatialComponent = entity.getComponent(SpatialComponent.class);
    Spatial spatial = spatialComponent.getSpatial();
    assertThat(spatial.getX(), IsEqual.equalTo(100f));
    assertThat(spatial.getY(), IsEqual.equalTo(200f));
    HealthComponent healthComponent = entity.getComponent(HealthComponent.class);
    Container health = healthComponent.getHealth();
    assertThat(health.getCurrent(), IsEqual.equalTo(53f));
    assertThat(health.getTotal(), IsEqual.equalTo(250f));
}
Also used : Entity(com.artemis.Entity) Container(com.gemserk.componentsengine.utils.Container) EntityFactoryImpl(com.gemserk.commons.artemis.templates.EntityFactoryImpl) Spatial(com.gemserk.commons.gdx.games.Spatial) EntityTemplate(com.gemserk.commons.artemis.templates.EntityTemplate) SpatialComponent(com.gemserk.commons.artemis.components.SpatialComponent) World(com.artemis.World) EntityFactory(com.gemserk.commons.artemis.templates.EntityFactory) 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