Search in sources :

Example 1 with RadarSensor

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

the class SensorEntity method addRadarSensor.

public SensorEntity addRadarSensor(String targetTag, Axis2D axis2D, float distance, float angle) {
    RadarSensor component = (RadarSensor) recoverComponent(SensorComponentsLookup.RadarSensor);
    if (component == null) {
        component = new RadarSensor(targetTag, axis2D, distance, angle);
    } else {
        component.targetTag = targetTag;
        component.axis2D = axis2D;
        component.distance = distance;
        component.angle = angle;
        component.collisionSignal = false;
    }
    addComponent(SensorComponentsLookup.RadarSensor, component);
    return this;
}
Also used : RadarSensor(ilargia.egdx.logicbricks.component.sensor.RadarSensor)

Example 2 with RadarSensor

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

the class CreateRadarSensorSystem method execute.

@Override
protected void execute(List<SensorEntity> entities) {
    Vector2[] vertices = new Vector2[8];
    vertices[0] = new Vector2();
    for (SensorEntity e : entities) {
        GameEntity gameEntity = Indexed.getInteractiveEntity(e.getLink().ownerEntity);
        RigidBody rigidBody = gameEntity.getRigidBody();
        RadarSensor radarSensor = e.getRadarSensor();
        if (radarSensor.angle < 180) {
            for (int i = 0; i < 7; i++) {
                float angle = (float) (i / 6.0 * radarSensor.angle) - (radarSensor.angle / 2) + (radarSensor.axis2D.ordinal() * 90);
                vertices[i + 1] = new Vector2(radarSensor.distance * MathUtils.cosDeg(angle), radarSensor.distance * MathUtils.sinDeg(angle));
            }
            FixtureDef radarFixture = bodyBuilder.fixtureDefBuilder().polygonShape(vertices).sensor().build();
            rigidBody.body.createFixture(radarFixture).setUserData("RadarSensor");
        }
    }
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) Vector2(com.badlogic.gdx.math.Vector2) SensorEntity(ilargia.egdx.logicbricks.gen.sensor.SensorEntity) RigidBody(ilargia.egdx.logicbricks.component.game.RigidBody) RadarSensor(ilargia.egdx.logicbricks.component.sensor.RadarSensor) FixtureDef(com.badlogic.gdx.physics.box2d.FixtureDef)

Example 3 with RadarSensor

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

the class SensorEntity method replaceRadarSensor.

public SensorEntity replaceRadarSensor(String targetTag, Axis2D axis2D, float distance, float angle) {
    RadarSensor component = (RadarSensor) recoverComponent(SensorComponentsLookup.RadarSensor);
    if (component == null) {
        component = new RadarSensor(targetTag, axis2D, distance, angle);
    } else {
        component.targetTag = targetTag;
        component.axis2D = axis2D;
        component.distance = distance;
        component.angle = angle;
        component.collisionSignal = false;
    }
    replaceComponent(SensorComponentsLookup.RadarSensor, component);
    return this;
}
Also used : RadarSensor(ilargia.egdx.logicbricks.component.sensor.RadarSensor)

Example 4 with RadarSensor

use of ilargia.egdx.logicbricks.component.sensor.RadarSensor 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;
                    }
                }
            }
        }
    }
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) SensorEntity(ilargia.egdx.logicbricks.gen.sensor.SensorEntity) RadarSensor(ilargia.egdx.logicbricks.component.sensor.RadarSensor)

Aggregations

RadarSensor (ilargia.egdx.logicbricks.component.sensor.RadarSensor)4 GameEntity (ilargia.egdx.logicbricks.gen.game.GameEntity)2 SensorEntity (ilargia.egdx.logicbricks.gen.sensor.SensorEntity)2 Vector2 (com.badlogic.gdx.math.Vector2)1 FixtureDef (com.badlogic.gdx.physics.box2d.FixtureDef)1 RigidBody (ilargia.egdx.logicbricks.component.game.RigidBody)1