Search in sources :

Example 1 with RadialGravityActuator

use of ilargia.egdx.logicbricks.component.actuator.RadialGravityActuator in project Entitas-Java by Rubentxu.

the class CreateRadialGravityActuatorSystem method execute.

@Override
protected void execute(List<ActuatorEntity> actuatorEntities) {
    for (ActuatorEntity e : actuatorEntities) {
        RadialGravityActuator actuator = e.getRadialGravityActuator();
        GameEntity owner = Indexed.getInteractiveEntity(e.getLink().ownerEntity);
        entitas.sensor.createEntity().addNearSensor("", actuator.radius, 0).addLink("RadialGravitySensor", owner.getCreationIndex());
    }
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) RadialGravityActuator(ilargia.egdx.logicbricks.component.actuator.RadialGravityActuator) ActuatorEntity(ilargia.egdx.logicbricks.gen.actuator.ActuatorEntity)

Example 2 with RadialGravityActuator

use of ilargia.egdx.logicbricks.component.actuator.RadialGravityActuator in project Entitas-Java by Rubentxu.

the class ActuatorEntity method replaceRadialGravityActuator.

public ActuatorEntity replaceRadialGravityActuator(float gravity, float radius, float gravityFactor) {
    RadialGravityActuator component = (RadialGravityActuator) recoverComponent(ActuatorComponentsLookup.RadialGravityActuator);
    if (component == null) {
        component = new RadialGravityActuator(gravity, radius, gravityFactor);
    } else {
        component.gravity = gravity;
        component.radius = radius;
        component.gravityFactor = gravityFactor;
    }
    replaceComponent(ActuatorComponentsLookup.RadialGravityActuator, component);
    return this;
}
Also used : RadialGravityActuator(ilargia.egdx.logicbricks.component.actuator.RadialGravityActuator)

Example 3 with RadialGravityActuator

use of ilargia.egdx.logicbricks.component.actuator.RadialGravityActuator in project Entitas-Java by Rubentxu.

the class ActuatorEntity method addRadialGravityActuator.

public ActuatorEntity addRadialGravityActuator(float gravity, float radius, float gravityFactor) {
    RadialGravityActuator component = (RadialGravityActuator) recoverComponent(ActuatorComponentsLookup.RadialGravityActuator);
    if (component == null) {
        component = new RadialGravityActuator(gravity, radius, gravityFactor);
    } else {
        component.gravity = gravity;
        component.radius = radius;
        component.gravityFactor = gravityFactor;
    }
    addComponent(ActuatorComponentsLookup.RadialGravityActuator, component);
    return this;
}
Also used : RadialGravityActuator(ilargia.egdx.logicbricks.component.actuator.RadialGravityActuator)

Example 4 with RadialGravityActuator

use of ilargia.egdx.logicbricks.component.actuator.RadialGravityActuator in project Entitas-Java by Rubentxu.

the class RadialGravityActuatorSystem method execute.

@Override
public void execute(float deltaTime) {
    for (ActuatorEntity e : group.getEntities()) {
        RadialGravityActuator actuator = e.getRadialGravityActuator();
        GameEntity owner = Indexed.getInteractiveEntity(e.getLink().ownerEntity);
        Vector2 planet_position = owner.getRigidBody().body.getWorldCenter();
        SensorEntity gravitySensor = Indexed.getSensorsEntity(e.getLink().ownerEntity, "RadialGravitySensor");
        for (int index : gravitySensor.getNearSensor().distanceContactList) {
            GameEntity gameEntity = Indexed.getInteractiveEntity(index);
            body = gameEntity.getRigidBody().body;
            debris_position = body.getWorldCenter();
            planet_distance.set(0, 0);
            planet_distance.add(debris_position);
            planet_distance.sub(planet_position);
            force = -(float) ((actuator.gravity * body.getMass()) / planet_distance.len());
            if (planet_distance.len() < actuator.radius * actuator.gravityFactor) {
                planet_distance.scl(force);
                body.applyForceToCenter(planet_distance, true);
                float desiredAngle = MathUtils.atan2(-body.getLinearVelocity().x, body.getLinearVelocity().y);
                while (desiredAngle < -180 * MathUtils.degreesToRadians) desiredAngle += 360 * MathUtils.degreesToRadians;
                while (desiredAngle > 180 * MathUtils.degreesToRadians) desiredAngle -= 360 * MathUtils.degreesToRadians;
                body.applyTorque(desiredAngle < 0 ? planet_distance.nor().len() / 2 : -planet_distance.nor().len() / 2, true);
            }
        }
    }
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) Vector2(com.badlogic.gdx.math.Vector2) SensorEntity(ilargia.egdx.logicbricks.gen.sensor.SensorEntity) RadialGravityActuator(ilargia.egdx.logicbricks.component.actuator.RadialGravityActuator) ActuatorEntity(ilargia.egdx.logicbricks.gen.actuator.ActuatorEntity)

Aggregations

RadialGravityActuator (ilargia.egdx.logicbricks.component.actuator.RadialGravityActuator)4 ActuatorEntity (ilargia.egdx.logicbricks.gen.actuator.ActuatorEntity)2 GameEntity (ilargia.egdx.logicbricks.gen.game.GameEntity)2 Vector2 (com.badlogic.gdx.math.Vector2)1 SensorEntity (ilargia.egdx.logicbricks.gen.sensor.SensorEntity)1