use of ilargia.egdx.logicbricks.gen.game.GameEntity 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;
}
}
}
}
}
use of ilargia.egdx.logicbricks.gen.game.GameEntity 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.gen.game.GameEntity 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);
}
}
}
}
use of ilargia.egdx.logicbricks.gen.game.GameEntity in project Entitas-Java by Rubentxu.
the class RigidBodySystem method execute.
@Override
protected void execute(List<GameEntity> entities) {
for (GameEntity e : entities) {
Body body = e.getRigidBody().body;
body.setUserData(e.getCreationIndex());
}
}
use of ilargia.egdx.logicbricks.gen.game.GameEntity in project Entitas-Java by Rubentxu.
the class ActuatorEntity method addCameraActuator.
public ActuatorEntity addCameraActuator(Camera camera, short height, float damping, float minDistanceX, float minDistanceY, String followTagEntity) {
CameraActuator component = (CameraActuator) recoverComponent(ActuatorComponentsLookup.CameraActuator);
if (component == null) {
component = new CameraActuator(camera, height, damping, minDistanceX, minDistanceY, followTagEntity);
} else {
component.actuator = (indexOwner) -> {
Set<GameEntity> followEntities = Indexed.getTagEntities(followTagEntity);
for (GameEntity followEntity : followEntities) {
RigidBody rc = followEntity.getRigidBody();
Transform transform = rc.body.getTransform();
Vector3 position = camera.position;
position.x += (transform.getPosition().x + minDistanceX - position.x) * damping;
position.y += (transform.getPosition().y + minDistanceY - position.y) * height;
}
};
}
addComponent(ActuatorComponentsLookup.CameraActuator, component);
return this;
}
Aggregations