use of com.gemserk.commons.gdx.games.Spatial in project commons-gdx by gemserk.
the class PreviousStateSpatialSystem method processEntities.
@Override
protected void processEntities() {
RandomAccessMap<Entity, EntityComponents> allTheEntityComponents = factory.entityComponents;
int entitiesSize = allTheEntityComponents.size();
for (int e = 0; e < entitiesSize; e++) {
EntityComponents entityComponents = allTheEntityComponents.get(e);
SpatialComponent spatialComponent = entityComponents.spatialComponent;
PreviousStateSpatialComponent previousStateSpatialComponent = entityComponents.previousStateSpatialComponent;
Spatial spatial = spatialComponent.getSpatial();
Spatial previousSpatial = previousStateSpatialComponent.getSpatial();
previousSpatial.set(spatial);
}
}
use of com.gemserk.commons.gdx.games.Spatial in project commons-gdx by gemserk.
the class MovementSystem method processEntities.
@Override
protected void processEntities() {
RandomAccessMap<Entity, EntityComponents> allTheEntityComponents = componentsHolder.entityComponents;
int entitiesSize = allTheEntityComponents.size();
float delta = GlobalTime.getDelta();
for (int entityIndex = 0; entityIndex < entitiesSize; entityIndex++) {
EntityComponents entityComponents = allTheEntityComponents.get(entityIndex);
MovementComponent movementComponent = entityComponents.movementComponent;
Spatial spatial = entityComponents.spatialComponent.getSpatial();
Vector2 velocity = movementComponent.getVelocity();
tmpVelocity.set(velocity).mul(delta);
tmpPosition.set(spatial.getX(), spatial.getY()).add(tmpVelocity);
float newAngle = spatial.getAngle() + delta * movementComponent.getAngularVelocity();
spatial.setAngle(newAngle);
spatial.setPosition(tmpPosition.x, tmpPosition.y);
}
}
use of com.gemserk.commons.gdx.games.Spatial in project commons-gdx by gemserk.
the class TextLocationUpdateSystem method process.
@Override
protected void process(Entity e) {
SpatialComponent spatialComponent = Components.getSpatialComponent(e);
TextComponent textComponent = Components.getTextComponent(e);
Spatial spatial = spatialComponent.getSpatial();
textComponent.x = spatial.getX();
textComponent.y = spatial.getY();
}
use of com.gemserk.commons.gdx.games.Spatial in project commons-gdx by gemserk.
the class RenderLayerSpriteBatchImpl method render.
@Override
public void render() {
camera.getFrustum(frustum);
if (optimizationParameters.updateCamera)
camera.apply(spriteBatch);
RandomAccessMap<Entity, EntityComponents> entityComponents = factory.entityComponents;
if (blending && !spriteBatch.isBlendingEnabled())
spriteBatch.enableBlending();
else if (!blending && spriteBatch.isBlendingEnabled())
spriteBatch.disableBlending();
if (optimizationParameters.beginBatch)
spriteBatch.begin();
for (int i = 0; i < orderedByLayerRenderables.size(); i++) {
Renderable renderable = orderedByLayerRenderables.get(i);
if (!renderable.isVisible())
continue;
EntityComponents components = entityComponents.get(renderable.getEntity());
FrustumCullingComponent frustumCullingComponent = components.frustumCullingComponent;
if (frustumCullingComponent != null) {
Spatial spatial = components.spatialComponent.getSpatial();
entityBounds.set(frustumCullingComponent.bounds);
entityBounds.setX(entityBounds.getX() + spatial.getX());
entityBounds.setY(entityBounds.getY() + spatial.getY());
if (!frustum.overlaps(entityBounds))
continue;
}
SpriteComponent spriteComponent = components.spriteComponent;
if (spriteComponent != null) {
Sprite sprite = spriteComponent.getSprite();
sprite.setColor(spriteComponent.getColor());
sprite.draw(spriteBatch);
}
// don't like it will be asking for components all the time.
TextComponent textComponent = components.textComponent;
if (textComponent != null) {
BitmapFont font = textComponent.font;
if (font.getScaleX() != textComponent.scale) {
font.setScale(textComponent.scale);
}
font.setColor(textComponent.color);
//
SpriteBatchUtils.drawMultilineText(//
spriteBatch, //
font, textComponent.text, textComponent.x, textComponent.y, textComponent.cx, textComponent.cy);
}
ParticleEmitterComponent particleEmitterComponent = components.particleEmitterComponent;
if (particleEmitterComponent != null) {
particleEmitterComponent.particleEmitter.draw(spriteBatch);
}
}
if (optimizationParameters.endBatch)
spriteBatch.end();
}
use of com.gemserk.commons.gdx.games.Spatial 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));
}
Aggregations