Search in sources :

Example 6 with Spatial

use of com.gemserk.commons.gdx.games.Spatial 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)

Example 7 with Spatial

use of com.gemserk.commons.gdx.games.Spatial in project commons-gdx by gemserk.

the class SpriteUpdateSystem method processEntities.

@Override
protected void processEntities() {
    RandomAccessMap<Entity, EntityComponents> allTheEntityComponents = factory.entityComponents;
    int entitiesSize = allTheEntityComponents.size();
    for (int entityIndex = 0; entityIndex < entitiesSize; entityIndex++) {
        EntityComponents components = allTheEntityComponents.get(entityIndex);
        SpatialComponent spatialComponent = components.spatialComponent;
        SpriteComponent spriteComponent = components.spriteComponent;
        PreviousStateSpatialComponent previousStateSpatialComponent = components.previousStateSpatialComponent;
        Spatial spatial = spatialComponent.getSpatial();
        float x = spatial.getX();
        float y = spatial.getY();
        float angle = spatial.getAngle();
        if (previousStateSpatialComponent != null) {
            float interpolationAlpha = timeStepProvider.getAlpha();
            Spatial previousSpatial = previousStateSpatialComponent.getSpatial();
            x = FloatInterpolator.interpolate(previousSpatial.getX(), spatial.getX(), interpolationAlpha);
            y = FloatInterpolator.interpolate(previousSpatial.getY(), spatial.getY(), interpolationAlpha);
            float angleDiff = (float) AngleUtils.minimumDifference(previousSpatial.getAngle(), spatial.getAngle());
            angle = FloatInterpolator.interpolate(spatial.getAngle() - angleDiff, spatial.getAngle(), interpolationAlpha);
        }
        spriteComponent.update(x, y, spatial.getWidth(), spatial.getHeight(), angle);
    }
}
Also used : Entity(com.artemis.Entity) SpriteComponent(com.gemserk.commons.artemis.components.SpriteComponent) Spatial(com.gemserk.commons.gdx.games.Spatial) PreviousStateSpatialComponent(com.gemserk.commons.artemis.components.PreviousStateSpatialComponent) SpatialComponent(com.gemserk.commons.artemis.components.SpatialComponent) PreviousStateSpatialComponent(com.gemserk.commons.artemis.components.PreviousStateSpatialComponent)

Example 8 with Spatial

use of com.gemserk.commons.gdx.games.Spatial in project commons-gdx by gemserk.

the class ParticleEmitterSystem method process.

@Override
protected void process(Entity e) {
    SpatialComponent spatialComponent = Components.getSpatialComponent(e);
    Spatial spatial = spatialComponent.getSpatial();
    ParticleEmitterComponent particleEmitterComponent = Components.getParticleEmitterComponent(e);
    particleEmitterComponent.particleEmitter.setPosition(spatial.getX(), spatial.getY());
    particleEmitterComponent.particleEmitter.update(GlobalTime.getDelta());
}
Also used : Spatial(com.gemserk.commons.gdx.games.Spatial) SpatialComponent(com.gemserk.commons.artemis.components.SpatialComponent) ParticleEmitterComponent(com.gemserk.commons.artemis.components.ParticleEmitterComponent)

Aggregations

Spatial (com.gemserk.commons.gdx.games.Spatial)8 Entity (com.artemis.Entity)6 SpatialComponent (com.gemserk.commons.artemis.components.SpatialComponent)6 World (com.artemis.World)2 ParticleEmitterComponent (com.gemserk.commons.artemis.components.ParticleEmitterComponent)2 PreviousStateSpatialComponent (com.gemserk.commons.artemis.components.PreviousStateSpatialComponent)2 SpriteComponent (com.gemserk.commons.artemis.components.SpriteComponent)2 TextComponent (com.gemserk.commons.artemis.components.TextComponent)2 EntityFactory (com.gemserk.commons.artemis.templates.EntityFactory)2 EntityFactoryImpl (com.gemserk.commons.artemis.templates.EntityFactoryImpl)2 EntityTemplate (com.gemserk.commons.artemis.templates.EntityTemplate)2 Container (com.gemserk.componentsengine.utils.Container)2 Test (org.junit.Test)2 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)1 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)1 Vector2 (com.badlogic.gdx.math.Vector2)1 FrustumCullingComponent (com.gemserk.commons.artemis.components.FrustumCullingComponent)1 MovementComponent (com.gemserk.commons.artemis.components.MovementComponent)1 Renderable (com.gemserk.commons.artemis.render.Renderable)1