use of ilargia.egdx.logicbricks.gen.sensor.SensorEntity 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);
}
}
}
}
use of ilargia.egdx.logicbricks.gen.sensor.SensorEntity in project Entitas-Java by Rubentxu.
the class NearSensorSystem method processCollision.
@Override
public void processCollision(Fixture colliderA, Fixture colliderB, boolean collisionSignal) {
if (colliderA.isSensor() && !colliderB.isSensor()) {
Integer indexEntityA = (Integer) colliderA.getBody().getUserData();
Integer indexEntityB = (Integer) colliderB.getBody().getUserData();
String tagSensorA = (String) colliderA.getUserData();
Body bodyB = colliderB.getBody();
for (Fixture fixture : bodyB.getFixtureList()) {
if (fixture.isSensor())
return;
}
if (indexEntityA != null && indexEntityB != null && tagSensorA != null) {
GameEntity entityA = Indexed.getInteractiveEntity(indexEntityA);
GameEntity entityB = Indexed.getInteractiveEntity(indexEntityB);
if (entityA != null && entityB != null && tagSensorA != null) {
for (SensorEntity entity : sensorGroup.getEntities()) {
if (entity.getLink().ownerEntity == indexEntityA) {
NearSensor sensor = entity.getNearSensor();
if (sensor.targetTag != null && entityB.getTags().values.contains(sensor.targetTag)) {
if (collisionSignal) {
if (tagSensorA.equals("NearSensor")) {
sensor.distanceContactList.add(indexEntityB);
if (entity.getLink().sensorReference.contains("RadialGravity")) {
bodyB.setGravityScale(0);
bodyB.resetMassData();
}
} else if (tagSensorA.equals("ResetNearSensor")) {
sensor.resetDistanceContactList.add(indexEntityB);
}
} else {
if (tagSensorA.equals("NearSensor")) {
sensor.distanceContactList.remove(indexEntityB);
if (entity.getLink().sensorReference.contains("RadialGravity")) {
bodyB.setGravityScale(1);
bodyB.resetMassData();
}
} else if (tagSensorA.equals("ResetNearSensor")) {
sensor.resetDistanceContactList.remove(indexEntityB);
}
}
}
}
}
}
}
}
}
use of ilargia.egdx.logicbricks.gen.sensor.SensorEntity in project Entitas-Java by Rubentxu.
the class RadarSensorSystem method processCollision.
@Override
public void processCollision(Fixture colliderA, Fixture colliderB, boolean collisionSignal) {
if (colliderA.isSensor() && !colliderB.isSensor()) {
Integer indexEntityA = (Integer) colliderA.getBody().getUserData();
Integer indexEntityB = (Integer) colliderB.getBody().getUserData();
String tagSensorA = (String) colliderA.getUserData();
if (indexEntityA != null && indexEntityB != null && tagSensorA != null && tagSensorA.equals("RadarSensor")) {
GameEntity entityB = Indexed.getInteractiveEntity(indexEntityB);
if (entityB != null) {
for (SensorEntity entity : sensorGroup.getEntities()) {
RadarSensor radar = entity.getRadarSensor();
if (entityB.getTags().values.contains(radar.targetTag)) {
if (collisionSignal) {
Indexed.addEntityInSensor(entity, entityB);
} else {
Indexed.removeEntityInSensor(entity, entityB);
}
radar.collisionSignal = collisionSignal;
}
}
}
}
}
}
Aggregations