Java Code Examples for com.artemis.Entity#addComponent()

The following examples show how to use com.artemis.Entity#addComponent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityManglerSystem.java    From entity-system-benchmarks with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private final void createEntity() {
	Entity e = world.createEntity();
	Array<Class<? extends Component>> components = permutations[cmp[cmpIndex++]];
	if (cmpIndex == cmp.length) cmpIndex = 0;
	
	Object[] data = components.items;
	for (int i = 0, s = components.size; s > i; i++) {
		e.addComponent(world.createComponent((Class<Component>) data[i]));
	}
	e.addToWorld();
}
 
Example 2
Source File: EntityManglerSystem.java    From entity-system-benchmarks with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private final void createEntity() {
	Entity e = world.createEntity();
	Bag<Class<? extends Component>> components = permutations[cmp[cmpIndex++]];
	if (cmpIndex == cmp.length) cmpIndex = 0;
	
	Object[] data = components.getData();
	for (int i = 0, s = components.size(); s > i; i++) {
		e.addComponent(newInstance(data[i]));
	}
	e.addToWorld();
}
 
Example 3
Source File: EntityDeleterSystem.java    From entity-system-benchmarks with Apache License 2.0 4 votes vote down vote up
protected final void createEntity() {
	Entity e = world.createEntity();
	e.addComponent(world.createComponent(c1));
	e.addComponent(world.createComponent(c2));
	e.addToWorld();
}
 
Example 4
Source File: ArtemisBenchmark.java    From ashley with Apache License 2.0 4 votes vote down vote up
private static World prepareWorld (int numEntities) {
	World world = new World();

	world.setSystem(new MovementSystem());
	world.setSystem(new StateSystem());
	world.setSystem(new CollisionSystem());
	world.setSystem(new RemovalSystem());

	world.initialize();

	for (int i = 0; i < numEntities; ++i) {
		Entity entity = world.createEntity();

		if (Constants.shouldHaveComponent(ComponentType.POSITION, i)) {
			PositionComponent pos = new PositionComponent();
			pos.pos.x = MathUtils.random(Constants.MIN_POS, Constants.MAX_POS);
			pos.pos.y = MathUtils.random(Constants.MIN_POS, Constants.MAX_POS);
			entity.addComponent(pos);
		}

		if (Constants.shouldHaveComponent(ComponentType.MOVEMENT, i)) {
			MovementComponent mov = new MovementComponent();
			mov.velocity.x = MathUtils.random(Constants.MIN_VEL, Constants.MAX_VEL);
			mov.velocity.y = MathUtils.random(Constants.MIN_VEL, Constants.MAX_VEL);
			mov.accel.x = MathUtils.random(Constants.MIN_ACC, Constants.MAX_ACC);
			mov.accel.y = MathUtils.random(Constants.MIN_ACC, Constants.MAX_ACC);

			entity.addComponent(mov);
		}

		if (Constants.shouldHaveComponent(ComponentType.RADIUS, i)) {
			RadiusComponent rad = new RadiusComponent();
			rad.radius = MathUtils.random(Constants.MIN_RADIUS, Constants.MAX_RADIUS);
			entity.addComponent(rad);
		}

		if (Constants.shouldHaveComponent(ComponentType.STATE, i)) {
			entity.addComponent(new StateComponent());
		}

		world.addEntity(entity);
	}

	return world;
}