use of ilargia.egdx.logicbricks.component.sensor.Link in project Entitas-Java by Rubentxu.
the class RaySensorSystem method query.
@Override
protected boolean query(SensorEntity sensorEntity, float deltaTime) {
RaySensor sensor = sensorEntity.getRaySensor();
sensor.rayContactList.clear();
sensor.collisionSignal = false;
Link link = sensorEntity.getLink();
float angle = sensor.axis2D.ordinal() * 90.0f;
GameEntity originEntity = Indexed.getInteractiveEntity(link.ownerEntity);
Vector2 point1 = originEntity.getRigidBody().body.getPosition();
Vector2 point2 = point1.cpy().add(new Vector2((float) MathUtils.cosDeg(angle), MathUtils.sinDeg(angle)).scl(sensor.range));
physics.rayCast((fixture, point, normal, fraction) -> reportRayFixture(sensor, fixture), point1, point2);
return sensor.collisionSignal;
}
use of ilargia.egdx.logicbricks.component.sensor.Link in project Entitas-Java by Rubentxu.
the class SensorSystem method process.
public void process(SensorEntity sensor, float deltaTime) {
Link link = sensor.getLink();
boolean lastPulse = link.pulse;
link.pulse = query(sensor, deltaTime);
if (sensor.hasFrequency()) {
Frequency frequency = sensor.getFrequency();
if ((frequency.time += deltaTime) >= frequency.tick) {
if (sensor.hasMode()) {
link.isOpen = link.isChanged || (sensor.getMode().type == link.pulse);
} else {
link.isOpen = link.isChanged;
}
frequency.time = 0;
} else {
link.isOpen = false;
}
} else {
if (sensor.hasMode()) {
link.isOpen = (lastPulse != link.pulse) || (sensor.getMode().type == link.pulse);
} else {
link.isOpen = lastPulse != link.pulse;
}
}
link.isChanged = lastPulse != link.pulse;
}
use of ilargia.egdx.logicbricks.component.sensor.Link in project Entitas-Java by Rubentxu.
the class SensorEntity method addLink.
public SensorEntity addLink(String sensorReference, int ownerEntity) {
Link component = (Link) recoverComponent(SensorComponentsLookup.Link);
if (component == null) {
component = new Link(sensorReference, ownerEntity);
} else {
component.sensorReference = sensorReference;
component.ownerEntity = ownerEntity;
component.isOpen = false;
component.isChanged = false;
component.pulse = false;
}
addComponent(SensorComponentsLookup.Link, component);
return this;
}
use of ilargia.egdx.logicbricks.component.sensor.Link in project Entitas-Java by Rubentxu.
the class SensorEntity method replaceLink.
public SensorEntity replaceLink(String sensorReference, int ownerEntity) {
Link component = (Link) recoverComponent(SensorComponentsLookup.Link);
if (component == null) {
component = new Link(sensorReference, ownerEntity);
} else {
component.sensorReference = sensorReference;
component.ownerEntity = ownerEntity;
component.isOpen = false;
component.isChanged = false;
component.pulse = false;
}
replaceComponent(SensorComponentsLookup.Link, component);
return this;
}
Aggregations