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