Search in sources :

Example 6 with RigidBody

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

the class ActuatorEntity method addCameraActuator.

public ActuatorEntity addCameraActuator(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;
            }
        };
    }
    addComponent(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 7 with RigidBody

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

the class ActuatorEntity method replaceParticleEffectActuator.

public ActuatorEntity replaceParticleEffectActuator(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();
        };
    }
    replaceComponent(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 8 with RigidBody

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

the class ActuatorEntity method replaceVelocityActuator.

public ActuatorEntity replaceVelocityActuator(Vector2 velocity, float angularVelocity) {
    VelocityActuator component = (VelocityActuator) recoverComponent(ActuatorComponentsLookup.VelocityActuator);
    if (component == null) {
        component = new VelocityActuator(velocity, angularVelocity);
    } else {
        component.actuator = (indexOwner) -> {
            GameEntity owner = Indexed.getInteractiveEntity(indexOwner);
            RigidBody rigidBody = owner.getRigidBody();
            rigidBody.body.setLinearVelocity(velocity);
            rigidBody.body.setAngularVelocity(angularVelocity);
        };
    }
    replaceComponent(ActuatorComponentsLookup.VelocityActuator, component);
    return this;
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) RigidBody(ilargia.egdx.logicbricks.component.game.RigidBody) VelocityActuator(ilargia.egdx.logicbricks.component.actuator.VelocityActuator)

Example 9 with RigidBody

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

the class ActuatorEntity method addVelocityActuator.

public ActuatorEntity addVelocityActuator(Vector2 velocity, float angularVelocity) {
    VelocityActuator component = (VelocityActuator) recoverComponent(ActuatorComponentsLookup.VelocityActuator);
    if (component == null) {
        component = new VelocityActuator(velocity, angularVelocity);
    } else {
        component.actuator = (indexOwner) -> {
            GameEntity owner = Indexed.getInteractiveEntity(indexOwner);
            RigidBody rigidBody = owner.getRigidBody();
            rigidBody.body.setLinearVelocity(velocity);
            rigidBody.body.setAngularVelocity(angularVelocity);
        };
    }
    addComponent(ActuatorComponentsLookup.VelocityActuator, component);
    return this;
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) RigidBody(ilargia.egdx.logicbricks.component.game.RigidBody) VelocityActuator(ilargia.egdx.logicbricks.component.actuator.VelocityActuator)

Example 10 with RigidBody

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

the class GameEntity method replaceRigidBody.

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

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