Search in sources :

Example 1 with SpatialComponent

use of com.gemserk.commons.artemis.components.SpatialComponent 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);
    }
}
Also used : Entity(com.artemis.Entity) 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 2 with SpatialComponent

use of com.gemserk.commons.artemis.components.SpatialComponent 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();
}
Also used : TextComponent(com.gemserk.commons.artemis.components.TextComponent) Spatial(com.gemserk.commons.gdx.games.Spatial) SpatialComponent(com.gemserk.commons.artemis.components.SpatialComponent)

Example 3 with SpatialComponent

use of com.gemserk.commons.artemis.components.SpatialComponent 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));
}
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 4 with SpatialComponent

use of com.gemserk.commons.artemis.components.SpatialComponent 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 5 with SpatialComponent

use of com.gemserk.commons.artemis.components.SpatialComponent 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);
}
Also used : Entity(com.artemis.Entity) Script(com.gemserk.commons.artemis.scripts.Script) ScriptJavaImpl(com.gemserk.commons.artemis.scripts.ScriptJavaImpl) ScriptComponent(com.gemserk.commons.artemis.components.ScriptComponent) EntityTemplate(com.gemserk.commons.artemis.templates.EntityTemplate) SpatialComponent(com.gemserk.commons.artemis.components.SpatialComponent) World(com.artemis.World) ParametersWrapper(com.gemserk.componentsengine.utils.ParametersWrapper) EntityFactoryImpl(com.gemserk.commons.artemis.templates.EntityFactoryImpl) EntityFactory(com.gemserk.commons.artemis.templates.EntityFactory) Test(org.junit.Test)

Aggregations

SpatialComponent (com.gemserk.commons.artemis.components.SpatialComponent)7 Spatial (com.gemserk.commons.gdx.games.Spatial)6 Entity (com.artemis.Entity)5 World (com.artemis.World)3 EntityFactory (com.gemserk.commons.artemis.templates.EntityFactory)3 EntityFactoryImpl (com.gemserk.commons.artemis.templates.EntityFactoryImpl)3 EntityTemplate (com.gemserk.commons.artemis.templates.EntityTemplate)3 Test (org.junit.Test)3 PreviousStateSpatialComponent (com.gemserk.commons.artemis.components.PreviousStateSpatialComponent)2 Container (com.gemserk.componentsengine.utils.Container)2 ParticleEmitterComponent (com.gemserk.commons.artemis.components.ParticleEmitterComponent)1 ScriptComponent (com.gemserk.commons.artemis.components.ScriptComponent)1 SpriteComponent (com.gemserk.commons.artemis.components.SpriteComponent)1 TextComponent (com.gemserk.commons.artemis.components.TextComponent)1 Script (com.gemserk.commons.artemis.scripts.Script)1 ScriptJavaImpl (com.gemserk.commons.artemis.scripts.ScriptJavaImpl)1 ParametersWrapper (com.gemserk.componentsengine.utils.ParametersWrapper)1