Search in sources :

Example 1 with NearSensor

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;
}
Also used : NearSensor(ilargia.egdx.logicbricks.component.sensor.NearSensor)

Example 2 with NearSensor

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");
            }
        }
    }
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) SensorEntity(ilargia.egdx.logicbricks.gen.sensor.SensorEntity) RigidBody(ilargia.egdx.logicbricks.component.game.RigidBody) FixtureDef(com.badlogic.gdx.physics.box2d.FixtureDef) NearSensor(ilargia.egdx.logicbricks.component.sensor.NearSensor)

Example 3 with NearSensor

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;
}
Also used : NearSensor(ilargia.egdx.logicbricks.component.sensor.NearSensor)

Example 4 with NearSensor

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;
}
Also used : NearSensor(ilargia.egdx.logicbricks.component.sensor.NearSensor)

Example 5 with NearSensor

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);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) SensorEntity(ilargia.egdx.logicbricks.gen.sensor.SensorEntity) Fixture(com.badlogic.gdx.physics.box2d.Fixture) Body(com.badlogic.gdx.physics.box2d.Body) NearSensor(ilargia.egdx.logicbricks.component.sensor.NearSensor)

Aggregations

NearSensor (ilargia.egdx.logicbricks.component.sensor.NearSensor)5 GameEntity (ilargia.egdx.logicbricks.gen.game.GameEntity)2 SensorEntity (ilargia.egdx.logicbricks.gen.sensor.SensorEntity)2 Body (com.badlogic.gdx.physics.box2d.Body)1 Fixture (com.badlogic.gdx.physics.box2d.Fixture)1 FixtureDef (com.badlogic.gdx.physics.box2d.FixtureDef)1 RigidBody (ilargia.egdx.logicbricks.component.game.RigidBody)1