Search in sources :

Example 6 with SensorEntity

use of ilargia.egdx.logicbricks.gen.sensor.SensorEntity 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 7 with SensorEntity

use of ilargia.egdx.logicbricks.gen.sensor.SensorEntity in project Entitas-Java by Rubentxu.

the class NearSensorSystem 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();
        Body bodyB = colliderB.getBody();
        for (Fixture fixture : bodyB.getFixtureList()) {
            if (fixture.isSensor())
                return;
        }
        if (indexEntityA != null && indexEntityB != null && tagSensorA != null) {
            GameEntity entityA = Indexed.getInteractiveEntity(indexEntityA);
            GameEntity entityB = Indexed.getInteractiveEntity(indexEntityB);
            if (entityA != null && entityB != null && tagSensorA != null) {
                for (SensorEntity entity : sensorGroup.getEntities()) {
                    if (entity.getLink().ownerEntity == indexEntityA) {
                        NearSensor sensor = entity.getNearSensor();
                        if (sensor.targetTag != null && entityB.getTags().values.contains(sensor.targetTag)) {
                            if (collisionSignal) {
                                if (tagSensorA.equals("NearSensor")) {
                                    sensor.distanceContactList.add(indexEntityB);
                                    if (entity.getLink().sensorReference.contains("RadialGravity")) {
                                        bodyB.setGravityScale(0);
                                        bodyB.resetMassData();
                                    }
                                } else if (tagSensorA.equals("ResetNearSensor")) {
                                    sensor.resetDistanceContactList.add(indexEntityB);
                                }
                            } else {
                                if (tagSensorA.equals("NearSensor")) {
                                    sensor.distanceContactList.remove(indexEntityB);
                                    if (entity.getLink().sensorReference.contains("RadialGravity")) {
                                        bodyB.setGravityScale(1);
                                        bodyB.resetMassData();
                                    }
                                } else if (tagSensorA.equals("ResetNearSensor")) {
                                    sensor.resetDistanceContactList.remove(indexEntityB);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) SensorEntity(ilargia.egdx.logicbricks.gen.sensor.SensorEntity) Fixture(com.badlogic.gdx.physics.box2d.Fixture) Body(com.badlogic.gdx.physics.box2d.Body) NearSensor(ilargia.egdx.logicbricks.component.sensor.NearSensor)

Example 8 with SensorEntity

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

Aggregations

GameEntity (ilargia.egdx.logicbricks.gen.game.GameEntity)8 SensorEntity (ilargia.egdx.logicbricks.gen.sensor.SensorEntity)8 Vector2 (com.badlogic.gdx.math.Vector2)3 Body (com.badlogic.gdx.physics.box2d.Body)2 FixtureDef (com.badlogic.gdx.physics.box2d.FixtureDef)2 RigidBody (ilargia.egdx.logicbricks.component.game.RigidBody)2 NearSensor (ilargia.egdx.logicbricks.component.sensor.NearSensor)2 RadarSensor (ilargia.egdx.logicbricks.component.sensor.RadarSensor)2 ActuatorEntity (ilargia.egdx.logicbricks.gen.actuator.ActuatorEntity)2 Animation (com.badlogic.gdx.graphics.g2d.Animation)1 ParticleEffect (com.badlogic.gdx.graphics.g2d.ParticleEffect)1 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)1 Fixture (com.badlogic.gdx.physics.box2d.Fixture)1 EngineGDX (ilargia.egdx.impl.EngineGDX)1 PhysicsManagerGDX (ilargia.egdx.impl.managers.PhysicsManagerGDX)1 Link (ilargia.egdx.logicbricks.component.actuator.Link)1 RadialGravityActuator (ilargia.egdx.logicbricks.component.actuator.RadialGravityActuator)1 CollisionSensor (ilargia.egdx.logicbricks.component.sensor.CollisionSensor)1 Bounds (ilargia.egdx.logicbricks.data.Bounds)1 BodyBuilder (ilargia.egdx.util.BodyBuilder)1