Search in sources :

Example 1 with Container

use of com.gemserk.componentsengine.utils.Container 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)

Example 2 with Container

use of com.gemserk.componentsengine.utils.Container in project commons-gdx by gemserk.

the class EntityTemplateTest method testModifyPositionByHand.

@Test
public void testModifyPositionByHand() {
    // default parameters through a custom template, could be created when the level starts with custom level information
    EntityTemplate customShipTemplate = new ShipEntityTemplate() {

        {
            parameters.put("health", new Container(250f, 250f));
        }
    };
    EntityFactory entityFactory = new EntityFactoryImpl(new World());
    Entity entity = entityFactory.instantiate(customShipTemplate);
    SpatialComponent spatialComponent = entity.getComponent(SpatialComponent.class);
    Spatial spatial = spatialComponent.getSpatial();
    spatial.setPosition(100f, 100f);
}
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)2 World (com.artemis.World)2 SpatialComponent (com.gemserk.commons.artemis.components.SpatialComponent)2 EntityFactory (com.gemserk.commons.artemis.templates.EntityFactory)2 EntityFactoryImpl (com.gemserk.commons.artemis.templates.EntityFactoryImpl)2 EntityTemplate (com.gemserk.commons.artemis.templates.EntityTemplate)2 Spatial (com.gemserk.commons.gdx.games.Spatial)2 Container (com.gemserk.componentsengine.utils.Container)2 Test (org.junit.Test)2