use of ilargia.egdx.logicbricks.gen.actuator.ActuatorEntity in project Entitas-Java by Rubentxu.
the class CreateRadialGravityActuatorSystem method execute.
@Override
protected void execute(List<ActuatorEntity> actuatorEntities) {
for (ActuatorEntity e : actuatorEntities) {
RadialGravityActuator actuator = e.getRadialGravityActuator();
GameEntity owner = Indexed.getInteractiveEntity(e.getLink().ownerEntity);
entitas.sensor.createEntity().addNearSensor("", actuator.radius, 0).addLink("RadialGravitySensor", owner.getCreationIndex());
}
}
use of ilargia.egdx.logicbricks.gen.actuator.ActuatorEntity in project Entitas-Java by Rubentxu.
the class Indexed method initialize.
public static void initialize(Entitas entitas) {
_entitas = entitas;
index = new KeyIndex(-1, null);
// GameEntity contains Sensors entities
_entitas.sensor.addEntityIndex(new PrimaryEntityIndex<SensorEntity, KeyIndex>(Indexed.SensorsEntityIndex, ((e, c) -> {
if (c != null) {
ilargia.egdx.logicbricks.component.sensor.Link link = (ilargia.egdx.logicbricks.component.sensor.Link) c;
return new KeyIndex(link.ownerEntity, link.sensorReference);
}
return new KeyIndex(e.getLink().ownerEntity, e.getLink().sensorReference);
}), _entitas.sensor.getGroup(SensorMatcher.Link())));
// GameEntity contains Actuator entities
_entitas.actuator.addEntityIndex(new PrimaryEntityIndex<ActuatorEntity, KeyIndex>(Indexed.ActuatorsEntityIndex, ((e, c) -> {
if (c != null) {
Link link = (Link) c;
return new KeyIndex(link.ownerEntity, link.actuatorReference);
}
return new KeyIndex(e.getLink().ownerEntity, e.getLink().actuatorReference);
}), _entitas.actuator.getGroup(ActuatorMatcher.Link())));
// Interactive GameEntity index
_entitas.game.addEntityIndex(new PrimaryEntityIndex<GameEntity, Integer>(Indexed.InteractiveEntityIndex, ((e, c) -> e.getCreationIndex()), _entitas.game.getGroup(GameMatcher.Interactive())));
// Tags GameEntity index
_entitas.game.addEntityIndex(new EntityIndex<GameEntity, String>(Indexed.TagEntityIndex, _entitas.game.getGroup(Matcher.AllOf(GameMatcher.Tags(), GameMatcher.Interactive())), ((e, c) -> e.getTags().values.toArray(new String[0]))));
// Sensors context GameEntities
_entitas.game.addEntityIndex(new EntityIndex<GameEntity, Integer>(Indexed.GameEntitiesInSensorIndex, _entitas.game.getGroup(GameMatcher.Interactive()), ((e, c) -> new Integer[0])));
}
use of ilargia.egdx.logicbricks.gen.actuator.ActuatorEntity in project Entitas-Java by Rubentxu.
the class TextureRendererSystem method render.
@Override
public void render() {
batch.setProjectionMatrix(cam.combined);
batch.begin();
for (GameEntity e : groupTextureView.getEntities()) {
TextureView view = e.getTextureView();
Body body = e.getRigidBody().body;
processTextureFlip(view);
batch.setColor(1f, 1f, 1f, 1f);
if (view.opacity < 1)
batch.setColor(1f, 1f, 1f, view.opacity);
batch.draw(view.texture, body.getPosition().x - view.bounds.extentsX, body.getPosition().y - view.bounds.extentsY, view.bounds.extentsX, view.bounds.extentsY, view.bounds.extentsX * 2, view.bounds.extentsY * 2, 1, 1, MathUtils.radiansToDegrees * body.getTransform().getRotation());
}
for (ActuatorEntity e : groupEffect.getEntities()) {
if (e.getLink().isOpen) {
ParticleEffectActuator effectActuator = e.getParticleEffectActuator();
effectActuator.particleEffect.draw(batch);
}
}
batch.end();
}
use of ilargia.egdx.logicbricks.gen.actuator.ActuatorEntity in project Entitas-Java by Rubentxu.
the class ActuatorSystem method execute.
@Override
public void execute(float deltaTime) {
for (ActuatorEntity e : groupTexture.getEntities()) {
if (e.getLink().isOpen) {
TextureActuator textureActuator = e.getTextureActuator();
textureActuator.actuator.execute(e.getLink().ownerEntity);
}
}
for (ActuatorEntity e : groupVelocity.getEntities()) {
if (e.getLink().isOpen) {
VelocityActuator velocityActuator = e.getVelocityActuator();
velocityActuator.actuator.execute(e.getLink().ownerEntity);
}
}
for (ActuatorEntity e : groupCamera.getEntities()) {
if (e.getLink().isOpen) {
CameraActuator cameraActuator = e.getCameraActuator();
cameraActuator.actuator.execute(e.getLink().ownerEntity);
}
}
for (ActuatorEntity e : groupEffect.getEntities()) {
if (e.getLink().isOpen) {
ParticleEffectActuator effectActuator = e.getParticleEffectActuator();
effectActuator.actuator.execute(e.getLink().ownerEntity);
}
}
}
use of ilargia.egdx.logicbricks.gen.actuator.ActuatorEntity in project Entitas-Java by Rubentxu.
the class RadialGravityActuatorSystem method execute.
@Override
public void execute(float deltaTime) {
for (ActuatorEntity e : group.getEntities()) {
RadialGravityActuator actuator = e.getRadialGravityActuator();
GameEntity owner = Indexed.getInteractiveEntity(e.getLink().ownerEntity);
Vector2 planet_position = owner.getRigidBody().body.getWorldCenter();
SensorEntity gravitySensor = Indexed.getSensorsEntity(e.getLink().ownerEntity, "RadialGravitySensor");
for (int index : gravitySensor.getNearSensor().distanceContactList) {
GameEntity gameEntity = Indexed.getInteractiveEntity(index);
body = gameEntity.getRigidBody().body;
debris_position = body.getWorldCenter();
planet_distance.set(0, 0);
planet_distance.add(debris_position);
planet_distance.sub(planet_position);
force = -(float) ((actuator.gravity * body.getMass()) / planet_distance.len());
if (planet_distance.len() < actuator.radius * actuator.gravityFactor) {
planet_distance.scl(force);
body.applyForceToCenter(planet_distance, true);
float desiredAngle = MathUtils.atan2(-body.getLinearVelocity().x, body.getLinearVelocity().y);
while (desiredAngle < -180 * MathUtils.degreesToRadians) desiredAngle += 360 * MathUtils.degreesToRadians;
while (desiredAngle > 180 * MathUtils.degreesToRadians) desiredAngle -= 360 * MathUtils.degreesToRadians;
body.applyTorque(desiredAngle < 0 ? planet_distance.nor().len() / 2 : -planet_distance.nor().len() / 2, true);
}
}
}
}
Aggregations