Search in sources :

Example 1 with CollisionSensor

use of ilargia.egdx.logicbricks.component.sensor.CollisionSensor in project Entitas-Java by Rubentxu.

the class SensorEntity method addCollisionSensor.

public SensorEntity addCollisionSensor(String targetTag) {
    CollisionSensor component = (CollisionSensor) recoverComponent(SensorComponentsLookup.CollisionSensor);
    if (component == null) {
        component = new CollisionSensor(targetTag);
    } else {
        component.targetTag = targetTag;
        component.collisionSignal = false;
    }
    addComponent(SensorComponentsLookup.CollisionSensor, component);
    return this;
}
Also used : CollisionSensor(ilargia.egdx.logicbricks.component.sensor.CollisionSensor)

Example 2 with CollisionSensor

use of ilargia.egdx.logicbricks.component.sensor.CollisionSensor in project Entitas-Java by Rubentxu.

the class SensorEntity method replaceCollisionSensor.

public SensorEntity replaceCollisionSensor(String targetTag) {
    CollisionSensor component = (CollisionSensor) recoverComponent(SensorComponentsLookup.CollisionSensor);
    if (component == null) {
        component = new CollisionSensor(targetTag);
    } else {
        component.targetTag = targetTag;
        component.collisionSignal = false;
    }
    replaceComponent(SensorComponentsLookup.CollisionSensor, component);
    return this;
}
Also used : CollisionSensor(ilargia.egdx.logicbricks.component.sensor.CollisionSensor)

Example 3 with CollisionSensor

use of ilargia.egdx.logicbricks.component.sensor.CollisionSensor in project Entitas-Java by Rubentxu.

the class CollisionSensorSystem method processCollision.

@Override
public void processCollision(Fixture colliderA, Fixture colliderB, boolean collisionSignal) {
    Integer indexEntityA = (Integer) colliderA.getBody().getUserData();
    Integer indexEntityB = (Integer) colliderB.getBody().getUserData();
    if (indexEntityA != null && indexEntityB != null) {
        GameEntity entityA = Indexed.getInteractiveEntity(indexEntityA);
        GameEntity entityB = Indexed.getInteractiveEntity(indexEntityB);
        if (entityA != null && entityB != null) {
            for (SensorEntity entity : sensorGroup.getEntities()) {
                CollisionSensor collision = entity.getCollisionSensor();
                if (entityB.getTags().values.contains(collision.targetTag)) {
                    if (collisionSignal) {
                        Indexed.addEntityInSensor(entity, entityB);
                    } else {
                        Indexed.removeEntityInSensor(entity, entityB);
                    }
                    collision.collisionSignal = collisionSignal;
                }
            }
        }
    }
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) SensorEntity(ilargia.egdx.logicbricks.gen.sensor.SensorEntity) CollisionSensor(ilargia.egdx.logicbricks.component.sensor.CollisionSensor)

Aggregations

CollisionSensor (ilargia.egdx.logicbricks.component.sensor.CollisionSensor)3 GameEntity (ilargia.egdx.logicbricks.gen.game.GameEntity)1 SensorEntity (ilargia.egdx.logicbricks.gen.sensor.SensorEntity)1