Search in sources :

Example 1 with RigidBody

use of ilargia.egdx.logicbricks.component.game.RigidBody in project Entitas-Java by Rubentxu.

the class CreateNearSensorSystem method execute.

@Override
protected void execute(List<SensorEntity> entities) {
    for (SensorEntity e : entities) {
        GameEntity gameEntity = Indexed.getInteractiveEntity(e.getLink().ownerEntity);
        RigidBody rigidBody = gameEntity.getRigidBody();
        NearSensor nearSensor = e.getNearSensor();
        if (nearSensor.distance > 0) {
            FixtureDef nearFixture = bodyBuilder.fixtureDefBuilder().circleShape(nearSensor.distance).sensor().build();
            rigidBody.body.createFixture(nearFixture).setUserData("NearSensor");
            if (nearSensor.resetDistance > nearSensor.distance) {
                FixtureDef nearResetFixture = bodyBuilder.fixtureDefBuilder().circleShape(nearSensor.resetDistance).sensor().build();
                rigidBody.body.createFixture(nearResetFixture).setUserData("ResetNearSensor");
            }
        }
    }
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) SensorEntity(ilargia.egdx.logicbricks.gen.sensor.SensorEntity) RigidBody(ilargia.egdx.logicbricks.component.game.RigidBody) FixtureDef(com.badlogic.gdx.physics.box2d.FixtureDef) NearSensor(ilargia.egdx.logicbricks.component.sensor.NearSensor)

Example 2 with RigidBody

use of ilargia.egdx.logicbricks.component.game.RigidBody in project Entitas-Java by Rubentxu.

the class ActuatorEntity method addParticleEffectActuator.

public ActuatorEntity addParticleEffectActuator(ParticleEffect effect, boolean autoStart, float locaPosX, float locaPosY) {
    ParticleEffectActuator component = (ParticleEffectActuator) recoverComponent(ActuatorComponentsLookup.ParticleEffectActuator);
    if (component == null) {
        component = new ParticleEffectActuator(effect, autoStart, locaPosX, locaPosY);
    } else {
        component.particleEffect = effect;
        component.actuator = (indexOwner) -> {
            GameEntity owner = Indexed.getInteractiveEntity(indexOwner);
            RigidBody rc = owner.getRigidBody();
            Transform transform = rc.body.getTransform();
            effect.setPosition(transform.getPosition().x + locaPosX, transform.getPosition().y + locaPosY);
            effect.update(Gdx.graphics.getDeltaTime());
            if (autoStart && effect.isComplete())
                effect.start();
        };
    }
    addComponent(ActuatorComponentsLookup.ParticleEffectActuator, component);
    return this;
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) ParticleEffectActuator(ilargia.egdx.logicbricks.component.actuator.ParticleEffectActuator) RigidBody(ilargia.egdx.logicbricks.component.game.RigidBody) Transform(com.badlogic.gdx.physics.box2d.Transform)

Example 3 with RigidBody

use of ilargia.egdx.logicbricks.component.game.RigidBody in project Entitas-Java by Rubentxu.

the class ActuatorEntity method replaceCameraActuator.

public ActuatorEntity replaceCameraActuator(Camera camera, short height, float damping, float minDistanceX, float minDistanceY, String followTagEntity) {
    CameraActuator component = (CameraActuator) recoverComponent(ActuatorComponentsLookup.CameraActuator);
    if (component == null) {
        component = new CameraActuator(camera, height, damping, minDistanceX, minDistanceY, followTagEntity);
    } else {
        component.actuator = (indexOwner) -> {
            Set<GameEntity> followEntities = Indexed.getTagEntities(followTagEntity);
            for (GameEntity followEntity : followEntities) {
                RigidBody rc = followEntity.getRigidBody();
                Transform transform = rc.body.getTransform();
                Vector3 position = camera.position;
                position.x += (transform.getPosition().x + minDistanceX - position.x) * damping;
                position.y += (transform.getPosition().y + minDistanceY - position.y) * height;
            }
        };
    }
    replaceComponent(ActuatorComponentsLookup.CameraActuator, component);
    return this;
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) CameraActuator(ilargia.egdx.logicbricks.component.actuator.CameraActuator) Vector3(com.badlogic.gdx.math.Vector3) RigidBody(ilargia.egdx.logicbricks.component.game.RigidBody) Transform(com.badlogic.gdx.physics.box2d.Transform)

Example 4 with RigidBody

use of ilargia.egdx.logicbricks.component.game.RigidBody in project Entitas-Java by Rubentxu.

the class GameEntity method addRigidBody.

public GameEntity addRigidBody(Body body) {
    RigidBody component = (RigidBody) recoverComponent(GameComponentsLookup.RigidBody);
    if (component == null) {
        component = new RigidBody();
    }
    component.body = body;
    addComponent(GameComponentsLookup.RigidBody, component);
    return this;
}
Also used : RigidBody(ilargia.egdx.logicbricks.component.game.RigidBody)

Example 5 with RigidBody

use of ilargia.egdx.logicbricks.component.game.RigidBody in project Entitas-Java by Rubentxu.

the class CreateRadarSensorSystem method execute.

@Override
protected void execute(List<SensorEntity> entities) {
    Vector2[] vertices = new Vector2[8];
    vertices[0] = new Vector2();
    for (SensorEntity e : entities) {
        GameEntity gameEntity = Indexed.getInteractiveEntity(e.getLink().ownerEntity);
        RigidBody rigidBody = gameEntity.getRigidBody();
        RadarSensor radarSensor = e.getRadarSensor();
        if (radarSensor.angle < 180) {
            for (int i = 0; i < 7; i++) {
                float angle = (float) (i / 6.0 * radarSensor.angle) - (radarSensor.angle / 2) + (radarSensor.axis2D.ordinal() * 90);
                vertices[i + 1] = new Vector2(radarSensor.distance * MathUtils.cosDeg(angle), radarSensor.distance * MathUtils.sinDeg(angle));
            }
            FixtureDef radarFixture = bodyBuilder.fixtureDefBuilder().polygonShape(vertices).sensor().build();
            rigidBody.body.createFixture(radarFixture).setUserData("RadarSensor");
        }
    }
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) Vector2(com.badlogic.gdx.math.Vector2) SensorEntity(ilargia.egdx.logicbricks.gen.sensor.SensorEntity) RigidBody(ilargia.egdx.logicbricks.component.game.RigidBody) RadarSensor(ilargia.egdx.logicbricks.component.sensor.RadarSensor) FixtureDef(com.badlogic.gdx.physics.box2d.FixtureDef)

Aggregations

RigidBody (ilargia.egdx.logicbricks.component.game.RigidBody)11 GameEntity (ilargia.egdx.logicbricks.gen.game.GameEntity)9 Transform (com.badlogic.gdx.physics.box2d.Transform)4 Vector3 (com.badlogic.gdx.math.Vector3)3 Vector2 (com.badlogic.gdx.math.Vector2)2 FixtureDef (com.badlogic.gdx.physics.box2d.FixtureDef)2 CameraActuator (ilargia.egdx.logicbricks.component.actuator.CameraActuator)2 ParticleEffectActuator (ilargia.egdx.logicbricks.component.actuator.ParticleEffectActuator)2 VelocityActuator (ilargia.egdx.logicbricks.component.actuator.VelocityActuator)2 SensorEntity (ilargia.egdx.logicbricks.gen.sensor.SensorEntity)2 TextureView (ilargia.egdx.logicbricks.component.game.TextureView)1 NearSensor (ilargia.egdx.logicbricks.component.sensor.NearSensor)1 RadarSensor (ilargia.egdx.logicbricks.component.sensor.RadarSensor)1