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;
}
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");
}
}
}
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;
}
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;
}
}
}
}
}
}
Aggregations