Search in sources :

Example 96 with Vector2

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

the class CoreEntity method replaceMotion.

public CoreEntity replaceMotion(float x, float y) {
    Motion component = (Motion) recoverComponent(CoreComponentsLookup.Motion);
    if (component == null) {
        component = new Motion(x, y);
    } else {
        component.velocity = new Vector2(x, y);
    }
    replaceComponent(CoreComponentsLookup.Motion, component);
    return this;
}
Also used : Motion(com.ilargia.games.logicbrick.component.Motion) Vector2(com.badlogic.gdx.math.Vector2)

Example 97 with Vector2

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

the class AddViewSystem method execute.

@Override
public void execute(List<GameEntity> entities) {
    for (GameEntity e : entities) {
        Texture texture = assetsManager.getTexture(String.format("assets/textures/%1$s.png", e.getAsset().name));
        Body body = bodyBuilder.fixture(new FixtureDefBuilder().boxShape(0.5f, 0.5f)).type(BodyDef.BodyType.KinematicBody).build();
        TextureRegion textureRegion = new TextureRegion(texture, 0, 0, texture.getWidth(), texture.getHeight());
        e.addTextureView(e.getAsset().name, textureRegion, body);
        //
        if (e.hasPosition()) {
            Position pos = e.getPosition();
            body.setTransform(new Vector2(pos.x, pos.y + 1), 0);
        }
    }
}
Also used : GameEntity(com.ilargia.games.logicbrick.gen.game.GameEntity) FixtureDefBuilder(com.ilargia.games.entitas.egdx.base.util.FixtureDefBuilder) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Position(com.ilargia.games.logicbrick.component.game.Position) Vector2(com.badlogic.gdx.math.Vector2) Texture(com.badlogic.gdx.graphics.Texture) Body(com.badlogic.gdx.physics.box2d.Body)

Example 98 with Vector2

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

the class PointerOverSensorSystem method isOver.

private boolean isOver(PointerOverSensor sensor, int pointer) {
    PointerState<Vector2, Vector3> touchState = inputManager.getTouchState(pointer);
    if (touchState.down) {
        Set<GameEntity> targets = Indexed.getTagEntities(sensor.targetTag);
        for (GameEntity target : targets) {
            TextureView view = target.getTextureView();
            RigidBody rigidBody = target.getRigidBody();
            if (view != null && rigidBody != null) {
                testRectangle.setPosition(rigidBody.body.getPosition().x, rigidBody.body.getPosition().y);
                testRectangle.setSize(view.bounds.extentsX * 2, view.bounds.extentsY * 2);
                return testRectangle.contains(touchState.coordinates.x, touchState.coordinates.y);
            }
        }
    }
    return false;
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) Vector2(com.badlogic.gdx.math.Vector2) Vector3(com.badlogic.gdx.math.Vector3) TextureView(ilargia.egdx.logicbricks.component.game.TextureView) RigidBody(ilargia.egdx.logicbricks.component.game.RigidBody)

Example 99 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 100 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