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());
}
}
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;
}
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;
}
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);
}
}
}
}
Aggregations