Search in sources :

Example 1 with MovementComponent

use of com.gemserk.commons.artemis.components.MovementComponent 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);
    }
}
Also used : Entity(com.artemis.Entity) Spatial(com.gemserk.commons.gdx.games.Spatial) Vector2(com.badlogic.gdx.math.Vector2) MovementComponent(com.gemserk.commons.artemis.components.MovementComponent)

Aggregations

Entity (com.artemis.Entity)1 Vector2 (com.badlogic.gdx.math.Vector2)1 MovementComponent (com.gemserk.commons.artemis.components.MovementComponent)1 Spatial (com.gemserk.commons.gdx.games.Spatial)1