Search in sources :

Example 91 with Vector2

use of com.badlogic.gdx.math.Vector2 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 92 with Vector2

use of com.badlogic.gdx.math.Vector2 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 93 with Vector2

use of com.badlogic.gdx.math.Vector2 in project Entitas-Java by Rubentxu.

the class InputManagerGDX method update.

@Override
public void update(float deltaTime) {
    //for every keystate, set pressed and released to false.
    for (int i = 0; i < 256; i++) {
        KeyState k = inputStateData.keyStates[i];
        k.pressed = false;
        k.released = false;
    }
    for (int i = 0; i < inputStateData.pointerStates.length; i++) {
        PointerState<Vector2, Vector3> t = inputStateData.pointerStates[i];
        if (t.down && !t.pressed)
            t.clickTime += deltaTime;
        t.pressed = false;
        t.released = false;
        t.displacement.x = 0;
        t.displacement.y = 0;
    }
    if (entitas.actuator.hasDragActuator() && jointDef == null) {
        this.dragActuator = entitas.actuator.getDragActuator();
        jointDef = new MouseJointDef();
        jointDef.bodyA = Indexed.getInteractiveEntity(dragActuator.targetEntity).getRigidBody().body;
        jointDef.collideConnected = dragActuator.collideConnected;
        jointDef.maxForce = dragActuator.maxForce;
    }
    for (GameController controller : controllers) {
        controller.update(this, entitas);
    }
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) GameController(ilargia.egdx.api.GameController) Vector3(com.badlogic.gdx.math.Vector3) KeyState(ilargia.egdx.api.managers.data.KeyState) MouseJoint(com.badlogic.gdx.physics.box2d.joints.MouseJoint) MouseJointDef(com.badlogic.gdx.physics.box2d.joints.MouseJointDef)

Example 94 with Vector2

use of com.badlogic.gdx.math.Vector2 in project Entitas-Java by Rubentxu.

the class PlatformExamples method createScene.

@Override
public void createScene(Engine engine, Entitas entitas) {
    AssetsManagerGDX assetsManager = engine.getManager(AssetsManagerGDX.class);
    assetsManager.loadTexture("assets/imagenes/fondos/fondo.jpg");
    assetsManager.loadTexture("assets/imagenes/fondos/nubes.png");
    assetsManager.loadTexture("assets/imagenes/fondos/arboles.png");
    assetsManager.finishLoading();
    //        entitas.scene.createEntity()
    //                .addParallaxLayer(new TextureRegion(assetsManager.getTexture("assets/imagenes/fondos/fondo.jpg"))
    //                        , new Vector2(0.7f,0f),new Vector2(0, 1),new Vector2(0, 0));
    entitas.scene.createEntity().addParallaxLayer(new TextureRegion(assetsManager.getTexture("assets/imagenes/fondos/nubes.png")), new Vector2(0.5f, 1.0f), new Vector2(0, 10), new Vector2(0, 0));
    entitas.scene.createEntity().addParallaxLayer(new TextureRegion(assetsManager.getTexture("assets/imagenes/fondos/arboles.png")), new Vector2(0.9f, 0), new Vector2(0, -0.4f), new Vector2(0, 0));
    //        entitas.scene.createEntity()
    //                .addCPointLight(55, Color.GOLD, 45, new Vector2(10,4));
    //        entitas.scene.createEntity()
    //                .addCChainLight(25, Color.FOREST, 180, 145, new float[]{-5, 0, 0, 0, 0, 0,30,12});
    //        entitas.scene.createEntity()
    //                .addCDirectionalLight(84, Color.SKY, 270);
    entitas.scene.createEntity().addCConeLight(35, Color.GREEN, 40, new Vector2(16, 13), 250, 60);
    SceneManagerGDX sceneManager = engine.getManager(SceneManagerGDX.class);
    GameEntity ground = sceneManager.createEntity("Ground");
    ground.getRigidBody().body.setTransform(10, 1, 0);
    GameEntity mariano = sceneManager.createEntity("Mariano");
    mariano.getRigidBody().body.setTransform(10, 6, 0);
    GameEntity box1 = sceneManager.createEntity("Box");
    box1.addTags("Box");
    box1.getRigidBody().body.setTransform(20, 7, 0);
    GameEntity box2 = sceneManager.createEntity("Box");
    box2.addTags("Box2");
    box2.getRigidBody().body.setTransform(25, 7, 0);
    entitas.actuator.setDragActuator(ground.getCreationIndex(), false, 1000);
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) AssetsManagerGDX(ilargia.egdx.impl.managers.AssetsManagerGDX) Vector2(com.badlogic.gdx.math.Vector2) SceneManagerGDX(ilargia.egdx.impl.managers.SceneManagerGDX)

Example 95 with Vector2

use of com.badlogic.gdx.math.Vector2 in project nhglib by VoidZombie.

the class InputHandler method processPointerInput.

private void processPointerInput(Integer pointer, NhgInput input) {
    if (config != null) {
        Vector2 axis = VectorPool.getVector2();
        PointerInputConfiguration conf = config.getPointerConfiguration(input.getName());
        switch(conf.getPointerSourceType()) {
            case POINTER_DELTA_XY:
                axis.set(Gdx.input.getDeltaX(pointer), Gdx.input.getDeltaY(pointer));
                axis.scl(conf.getHorizontalSensitivity(), conf.getVerticalSensitivity());
                break;
            case POINTER_XY:
                axis.set(Gdx.input.getX(pointer), Gdx.input.getY(pointer));
                break;
        }
        InputSource inputSource = input.getInputSource();
        inputSource.setName(input.getName());
        inputSource.setValue(axis);
    }
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) PointerInputConfiguration(io.github.voidzombie.nhglib.input.configuration.impls.PointerInputConfiguration)

Aggregations

Vector2 (com.badlogic.gdx.math.Vector2)103 Body (com.badlogic.gdx.physics.box2d.Body)21 BodyDef (com.badlogic.gdx.physics.box2d.BodyDef)14 FixtureDef (com.badlogic.gdx.physics.box2d.FixtureDef)10 PolygonShape (com.badlogic.gdx.physics.box2d.PolygonShape)10 Texture (com.badlogic.gdx.graphics.Texture)7 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)7 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)7 EdgeShape (com.badlogic.gdx.physics.box2d.EdgeShape)7 Vector3 (com.badlogic.gdx.math.Vector3)6 Fixture (com.badlogic.gdx.physics.box2d.Fixture)6 World (com.badlogic.gdx.physics.box2d.World)6 GameEntity (ilargia.egdx.logicbricks.gen.game.GameEntity)6 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)5 CircleShape (com.badlogic.gdx.physics.box2d.CircleShape)5 Test (org.junit.Test)5 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)4 Box2DDebugRenderer (com.badlogic.gdx.physics.box2d.Box2DDebugRenderer)4 Contact (com.badlogic.gdx.physics.box2d.Contact)4 WorldManifold (com.badlogic.gdx.physics.box2d.WorldManifold)4