Search in sources :

Example 16 with World

use of com.artemis.World 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 17 with World

use of com.artemis.World in project nhglib by VoidZombie.

the class EngineStateNotInitialized method enter.

@Override
public void enter(NhgEntry nhgEntry) {
    Logger.log(this, "Engine is not initialized.");
    // Setup the ECS world.
    WorldConfigurationBuilder configurationBuilder = new WorldConfigurationBuilder();
    // Configure user entity systems
    nhgEntry.onConfigureEntitySystems(configurationBuilder);
    // Configure the most important systems last, especially GraphicsSystem which
    // should be the last because it renders all the changes happened in all other
    // systems.
    configurationBuilder.with(new PhysicsSystem()).with(new CameraSystem()).with(new LightingSystem(nhgEntry.nhg.threading)).with(new GraphicsSystem(nhgEntry.nhg.entities, nhgEntry.nhg.messaging));
    nhgEntry.nhg.entities.setEntityWorld(new World(configurationBuilder.build()));
    nhgEntry.engineStarted();
    nhgEntry.getFsm().changeState(EngineStates.INITIALIZED);
}
Also used : PhysicsSystem(io.github.voidzombie.nhglib.runtime.ecs.systems.impl.PhysicsSystem) GraphicsSystem(io.github.voidzombie.nhglib.runtime.ecs.systems.impl.GraphicsSystem) CameraSystem(io.github.voidzombie.nhglib.runtime.ecs.systems.impl.CameraSystem) WorldConfigurationBuilder(com.artemis.WorldConfigurationBuilder) World(com.artemis.World) LightingSystem(io.github.voidzombie.nhglib.runtime.ecs.systems.impl.LightingSystem)

Example 18 with World

use of com.artemis.World 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 19 with World

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

the class EntityTemplateTest method weaponInstantiateBulletWithWeaponParameters.

@Test
public void weaponInstantiateBulletWithWeaponParameters() {
    // get the component from the weapon (the current entity)
    WeaponComponent weaponComponent = new WeaponComponent(560f, null);
    // custom template parameters of the weapon to be used when building a new bullet
    // this parameters are stored in each weapon instance.
    ParametersWrapper weaponBulletParameters = new ParametersWrapper();
    weaponBulletParameters.put("damage", weaponComponent.getDamage());
    // the interesting part here is that I could change it dynamically without changing the template or the instantiation call
    EntityTemplate bulletTemplate = new BulletEntityTemplate();
    EntityFactory entityFactory = new EntityFactoryImpl(new World());
    Entity bullet = entityFactory.instantiate(bulletTemplate, weaponBulletParameters);
    DamageComponent damageComponent = bullet.getComponent(DamageComponent.class);
    assertThat(damageComponent.getDamage(), IsEqual.equalTo(560f));
}
Also used : Entity(com.artemis.Entity) EntityFactoryImpl(com.gemserk.commons.artemis.templates.EntityFactoryImpl) EntityTemplate(com.gemserk.commons.artemis.templates.EntityTemplate) World(com.artemis.World) EntityFactory(com.gemserk.commons.artemis.templates.EntityFactory) ParametersWrapper(com.gemserk.componentsengine.utils.ParametersWrapper) Test(org.junit.Test)

Example 20 with World

use of com.artemis.World 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

World (com.artemis.World)39 Entity (com.artemis.Entity)38 Test (org.junit.Test)31 RenderableComponent (com.gemserk.commons.artemis.components.RenderableComponent)15 OwnerComponent (com.gemserk.commons.artemis.components.OwnerComponent)14 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 ContainerComponent (com.gemserk.commons.artemis.components.ContainerComponent)3 SpatialComponent (com.gemserk.commons.artemis.components.SpatialComponent)3 ParametersWrapper (com.gemserk.componentsengine.utils.ParametersWrapper)3 ComponentType (com.artemis.ComponentType)2 Spatial (com.gemserk.commons.gdx.games.Spatial)2 Container (com.gemserk.componentsengine.utils.Container)2 ComponentMapper (com.artemis.ComponentMapper)1 EntityProcessingSystem (com.artemis.EntityProcessingSystem)1 WorldConfigurationBuilder (com.artemis.WorldConfigurationBuilder)1 ScriptComponent (com.gemserk.commons.artemis.components.ScriptComponent)1 StoreComponent (com.gemserk.commons.artemis.components.StoreComponent)1