Search in sources :

Example 16 with GameEntity

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

Example 17 with GameEntity

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");
        }
    }
}
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 18 with GameEntity

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);
            }
        }
    }
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) Vector2(com.badlogic.gdx.math.Vector2) SensorEntity(ilargia.egdx.logicbricks.gen.sensor.SensorEntity) RadialGravityActuator(ilargia.egdx.logicbricks.component.actuator.RadialGravityActuator) ActuatorEntity(ilargia.egdx.logicbricks.gen.actuator.ActuatorEntity)

Example 19 with GameEntity

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());
    }
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) Body(com.badlogic.gdx.physics.box2d.Body)

Example 20 with GameEntity

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;
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) CameraActuator(ilargia.egdx.logicbricks.component.actuator.CameraActuator) Vector3(com.badlogic.gdx.math.Vector3) RigidBody(ilargia.egdx.logicbricks.component.game.RigidBody) Transform(com.badlogic.gdx.physics.box2d.Transform)

Aggregations

GameEntity (ilargia.egdx.logicbricks.gen.game.GameEntity)27 RigidBody (ilargia.egdx.logicbricks.component.game.RigidBody)9 SensorEntity (ilargia.egdx.logicbricks.gen.sensor.SensorEntity)8 Vector2 (com.badlogic.gdx.math.Vector2)6 Body (com.badlogic.gdx.physics.box2d.Body)5 TextureView (ilargia.egdx.logicbricks.component.game.TextureView)5 Transform (com.badlogic.gdx.physics.box2d.Transform)4 ActuatorEntity (ilargia.egdx.logicbricks.gen.actuator.ActuatorEntity)4 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)3 Vector3 (com.badlogic.gdx.math.Vector3)3 ParticleEffectActuator (ilargia.egdx.logicbricks.component.actuator.ParticleEffectActuator)3 FixtureDef (com.badlogic.gdx.physics.box2d.FixtureDef)2 PhysicsManagerGDX (ilargia.egdx.impl.managers.PhysicsManagerGDX)2 CameraActuator (ilargia.egdx.logicbricks.component.actuator.CameraActuator)2 RadialGravityActuator (ilargia.egdx.logicbricks.component.actuator.RadialGravityActuator)2 TextureActuator (ilargia.egdx.logicbricks.component.actuator.TextureActuator)2 VelocityActuator (ilargia.egdx.logicbricks.component.actuator.VelocityActuator)2 NearSensor (ilargia.egdx.logicbricks.component.sensor.NearSensor)2 RadarSensor (ilargia.egdx.logicbricks.component.sensor.RadarSensor)2 Bounds (ilargia.egdx.logicbricks.data.Bounds)2