use of com.artemis.World in project commons-gdx by gemserk.
the class EntityTemplateTest method weaponInstantiateBulletWithWeaponParametersWithStyle.
@Test
public void weaponInstantiateBulletWithWeaponParametersWithStyle() {
World world = new World();
final EntityFactory entityFactory = new EntityFactoryImpl(world);
EntityTemplate shipTemplate = new ShipEntityTemplate() {
{
parameters.put("x", 750f);
parameters.put("y", 125f);
}
};
Entity ship = entityFactory.instantiate(shipTemplate);
EntityTemplate weaponTemplate = new WeaponEntityTemplate();
EntityTemplate bulletTemplate = new BulletEntityTemplate();
ParametersWrapper weaponParameters = new ParametersWrapper();
weaponParameters.put("damage", 30f);
weaponParameters.put("bulletTemplate", bulletTemplate);
weaponParameters.put("owner", ship);
weaponParameters.put("script", new ScriptJavaImpl() {
ParametersWrapper bulletParameters = new ParametersWrapper();
@Override
public void update(World world, Entity e) {
WeaponComponent weaponComponent = e.getComponent(WeaponComponent.class);
OwnerComponent ownerComponent = e.getComponent(OwnerComponent.class);
Entity owner = ownerComponent.getOwner();
SpatialComponent spatialComponent = owner.getComponent(SpatialComponent.class);
bulletParameters.put("damage", weaponComponent.getDamage());
bulletParameters.put("position", spatialComponent.getPosition());
EntityTemplate bulletTemplate = weaponComponent.getBulletTemplate();
Entity bullet = entityFactory.instantiate(bulletTemplate, bulletParameters);
DamageComponent damageComponent = bullet.getComponent(DamageComponent.class);
SpatialComponent bulletSpatialComponent = bullet.getComponent(SpatialComponent.class);
// part of the test
assertThat(damageComponent.getDamage(), IsEqual.equalTo(30f));
assertThat(bulletSpatialComponent.getSpatial().getX(), IsEqual.equalTo(750f));
assertThat(bulletSpatialComponent.getSpatial().getY(), IsEqual.equalTo(125f));
}
});
Entity weapon = entityFactory.instantiate(weaponTemplate, weaponParameters);
// ... on script system
ScriptComponent scriptComponent = weapon.getComponent(ScriptComponent.class);
ArrayList<Script> scripts = scriptComponent.getScripts();
for (int i = 0; i < scripts.size(); i++) scripts.get(i).update(world, weapon);
}
use of com.artemis.World in project commons-gdx by gemserk.
the class GroupManagerTest method entityNotRemovedFromGroupWhenDeleted.
@Test
public void entityNotRemovedFromGroupWhenDeleted() {
String group = "EntityGroup";
World world = new World();
Entity e = world.createEntity();
e.setGroup(group);
e.refresh();
world.setDelta(10);
world.loopStart();
ImmutableBag<Entity> entities = world.getGroupManager().getEntities(group);
assertThat(entities.size(), IsEqual.equalTo(1));
world.deleteEntity(e);
world.setDelta(10);
world.loopStart();
entities = world.getGroupManager().getEntities(group);
assertThat(entities.size(), IsEqual.equalTo(0));
}
use of com.artemis.World in project commons-gdx by gemserk.
the class MultipleImplementationsSameComponentTest method shouldNotHandleSpecificComponentImplementation.
@Test
public void shouldNotHandleSpecificComponentImplementation() {
World world = new World();
WorldWrapper worldWrapper = new WorldWrapper(world);
worldWrapper.addUpdateSystem(new SecondImplementationSystem());
worldWrapper.init();
Entity e1 = world.createEntity();
e1.addComponent(new FirstImplementationComponent());
e1.refresh();
worldWrapper.update(100);
}
use of com.artemis.World in project commons-gdx by gemserk.
the class MultipleImplementationsSameComponentTest method shouldHandleParentComponentWithoutKnowingTheImplementation.
@Test
public void shouldHandleParentComponentWithoutKnowingTheImplementation() {
World world = new World();
WorldWrapper worldWrapper = new WorldWrapper(world);
worldWrapper.addUpdateSystem(new ParentSpatialSystem());
worldWrapper.addUpdateSystem(new FirstImplementationSystem());
worldWrapper.addUpdateSystem(new SecondImplementationSystem());
worldWrapper.init();
Entity e1 = world.createEntity();
e1.addComponent(new FirstImplementationComponent());
e1.refresh();
worldWrapper.update(100);
}
use of com.artemis.World in project commons-gdx by gemserk.
the class OrderedByLayerEntitiesTest method testOrderByInsertionOrder.
@Test
public void testOrderByInsertionOrder() {
World world = new World();
Entity e1 = world.createEntity();
Entity e2 = world.createEntity();
e1.addComponent(new RenderableComponent(5));
e2.addComponent(new RenderableComponent(5));
orderedByLayerEntities.add(e1);
orderedByLayerEntities.add(e2);
assertSame(orderedByLayerEntities.get(0), e1);
assertSame(orderedByLayerEntities.get(1), e2);
}
Aggregations