use of ilargia.egdx.logicbricks.component.sensor.NearSensor in project Entitas-Java by Rubentxu.
the class NearSensorSystem method query.
@Override
protected boolean query(SensorEntity sensorEntity, float deltaTime) {
boolean isActive = false;
NearSensor sensor = sensorEntity.getNearSensor();
if (sensor.distanceContactList.size() > 0) {
isActive = true;
if (!sensor.initContact)
sensor.initContact = true;
} else if (sensor.initContact && sensor.resetDistanceContactList.size() > 0) {
isActive = true;
} else if (sensor.initContact) {
sensor.initContact = false;
}
return isActive;
}
use of ilargia.egdx.logicbricks.component.sensor.NearSensor 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");
}
}
}
}
use of ilargia.egdx.logicbricks.component.sensor.NearSensor in project Entitas-Java by Rubentxu.
the class SensorEntity method replaceNearSensor.
public SensorEntity replaceNearSensor(String targetTag, float distance, float resetDistance) {
NearSensor component = (NearSensor) recoverComponent(SensorComponentsLookup.NearSensor);
if (component == null) {
component = new NearSensor(targetTag, distance, resetDistance);
} else {
component.targetTag = targetTag;
component.distance = distance;
component.resetDistance = resetDistance;
component.distanceContactList = EntitasCollections.createSet(Integer.class);
component.resetDistanceContactList = EntitasCollections.createSet(Integer.class);
}
replaceComponent(SensorComponentsLookup.NearSensor, component);
return this;
}
use of ilargia.egdx.logicbricks.component.sensor.NearSensor in project Entitas-Java by Rubentxu.
the class SensorEntity method addNearSensor.
public SensorEntity addNearSensor(String targetTag, float distance, float resetDistance) {
NearSensor component = (NearSensor) recoverComponent(SensorComponentsLookup.NearSensor);
if (component == null) {
component = new NearSensor(targetTag, distance, resetDistance);
} else {
component.targetTag = targetTag;
component.distance = distance;
component.resetDistance = resetDistance;
component.distanceContactList = EntitasCollections.createSet(Integer.class);
component.resetDistanceContactList = EntitasCollections.createSet(Integer.class);
}
addComponent(SensorComponentsLookup.NearSensor, component);
return this;
}
use of ilargia.egdx.logicbricks.component.sensor.NearSensor 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);
}
}
}
}
}
}
}
}
}
Aggregations