Example usage for com.badlogic.gdx.math Vector2 scl

List of usage examples for com.badlogic.gdx.math Vector2 scl

Introduction

In this page you can find the example usage for com.badlogic.gdx.math Vector2 scl.

Prototype

@Override
    public Vector2 scl(Vector2 v) 

Source Link

Usage

From source file:org.destinationsol.game.SolCam.java

License:Apache License

private void applyInput(SolGame game) {
    MainScreen s = game.getScreens().mainScreen;
    boolean d = s.isDown();
    boolean u = s.isUp();
    boolean l = s.isLeft();
    boolean r = s.isRight();
    Vector2 v = SolMath.getVec();
    if (l != r)//from   w  ww. j  a  v a 2  s .c o  m
        v.x = SolMath.toInt(r);
    if (d != u)
        v.y = SolMath.toInt(d);
    v.scl(MOVE_SPD * game.getTimeStep());
    SolMath.rotate(v, myAngle);
    myPos.add(v);
    SolMath.free(v);
}

From source file:org.destinationsol.game.SolCam.java

License:Apache License

public void drawDebug(GameDrawer drawer) {
    float hOver2 = VIEWPORT_HEIGHT * myZoom / 2;
    float wOver2 = hOver2 * drawer.r;
    Vector2 dr = SolMath.getVec(wOver2, hOver2);
    SolMath.rotate(dr, myAngle);/*www  .j a v  a2s .com*/
    Vector2 dl = SolMath.getVec(-wOver2, hOver2);
    SolMath.rotate(dl, myAngle);
    Vector2 ul = SolMath.getVec(dr);
    ul.scl(-1);
    Vector2 ur = SolMath.getVec(dl);
    ur.scl(-1);
    dr.add(myPos);
    dl.add(myPos);
    ul.add(myPos);
    ur.add(myPos);

    float lw = getRealLineWidth();
    drawer.drawLine(drawer.debugWhiteTex, dr, dl, SolColor.W, lw, false);
    drawer.drawLine(drawer.debugWhiteTex, dl, ul, SolColor.W, lw, false);
    drawer.drawLine(drawer.debugWhiteTex, ul, ur, SolColor.W, lw, false);
    drawer.drawLine(drawer.debugWhiteTex, ur, dr, SolColor.W, lw, false);

    SolMath.free(dr);
    SolMath.free(dl);
    SolMath.free(ul);
    SolMath.free(ur);
}

From source file:org.destinationsol.game.StarPort.java

License:Apache License

private static Vector2 adjustDesiredPos(SolGame game, StarPort myPort, Vector2 desired) {
    Vector2 newPos = desired;/*w w w .  j av  a2s.co m*/
    List<SolObject> objs = game.getObjMan().getObjs();
    for (SolObject o : objs) {
        if (o instanceof StarPort && o != myPort) {
            StarPort sp = (StarPort) o;
            // Check if the positions overlap
            Vector2 fromPos = sp.getPosition();
            Vector2 distVec = SolMath.distVec(fromPos, desired);
            float distance = SolMath.hypotenuse(distVec.x, distVec.y);
            if (distance <= (float) StarPort.SIZE) {
                distVec.scl((StarPort.SIZE + .5f) / distance);
                newPos = fromPos.cpy().add(distVec);
                Vector2 d2 = SolMath.distVec(fromPos, newPos);
                SolMath.free(d2);
            }
            SolMath.free(distVec);
        }
    }
    return newPos;
}

From source file:org.matheusdev.ror.controller.component.ComponentNetwork.java

License:Open Source License

@Override
public void apply(Entity entity) {
    Vector2 entityPos = entity.getPos();
    Vector2 posDiff = posDiffPool.set(remoteState.posX - entityPos.x, remoteState.posY - entityPos.y);
    float distance = posDiff.len();

    if (distance > 0.5f) {
        entity.getBody().setTransform(remoteState.posX, remoteState.posY, remoteState.angle);
        System.out.println("Set position to: " + remoteState.posX + ", " + remoteState.posY);
    } else if (distance > 0.1f) {
        entity.getBody().setTransform(entityPos.add(posDiff.scl(0.1f)), remoteState.angle);
    }/*from www.  ja v a2s  .co  m*/

    entity.getBody().setLinearVelocity(remoteState.velX, remoteState.velY);
}

From source file:org.saltosion.pixelprophecy.gui.nodes.GUINode.java

License:Open Source License

/**
 * Returns the pixel-perfect location of the node
 * @return /*  w ww.j  av a  2s .c  o  m*/
 */
public Vector2 getWorldLocation() {
    Vector2 loc = localTranslation.cpy();
    Vector2 alignmentOffset = alignment.cpy().scl(getSize()).scl(.5f);
    if (hasParent()) {
        loc.scl(parent.getSize().cpy().scl(.5f)).add(parent.getWorldLocation());
    }
    return loc.sub(alignmentOffset);
}

From source file:org.saltosion.pixelprophecy.input.GameInputAdapter.java

License:Open Source License

@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    Vector2 screenSize = new Vector2(Globals.VIEWPORT_HEIGHT * Globals.ASPECT_RATIO, Globals.VIEWPORT_HEIGHT);
    Vector2 pos = new Vector2(screenX * screenSize.x / Gdx.graphics.getWidth(),
            (Gdx.graphics.getHeight() - screenY) * screenSize.y / Gdx.graphics.getHeight());
    OrthographicCamera cam = gameState.getGameCamera();
    pos.add(cam.position.x, cam.position.y);
    pos.sub(screenSize.scl(.5f));
    System.out.println(pos);//www .j  a  v  a  2s. c  om
    return true;
}

From source file:org.saltosion.pixelprophecy.systems.MovementSystem.java

License:Open Source License

@Override
protected void processEntity(Entity entity, float deltaTime) {
    Comp.Physics physics = pm.get(entity);
    Vector2 dir = physics.destination.cpy().nor();
    physics.body.setLinearVelocity(dir.scl(physics.speed));
}

From source file:quantum.game.Bot.java

License:Open Source License

private void gatherConnectedPlanets(Simulation sim) {
    visited.clear();//from ww w  .j a  v  a 2 s. c  o  m
    unvisited.clear();
    components.clear();

    for (Planet planet : sim.getPlanets()) {
        if (planet.getOwner() != -1 && planet.getOwner() != this.id) {
            unvisited.add(planet);
        }
    }

    while (unvisited.size() != 0) {
        component_size = 0;
        Planet planet = unvisited.remove(0);
        Vector2 center = new Vector2();
        components.add(center);
        int num_planets = gatherConnectedPlanetsRecursive(sim, planet, center);
        center.scl(1.0f / num_planets);
    }
}

From source file:se.angergard.game.system.RemoveFloorSystem.java

License:Apache License

@SuppressWarnings("unchecked")
@Override//from  w  w w. j a v a2s  .c  om
public void init() {
    runnablePool = new RunnablePool();

    engine.addEntityListener(Family.getFor(RemoveFloorComponent.class), new EntityListener() {

        @Override
        public void entityAdded(final Entity entity) {
            runnablePool.add(new Runnable() {
                @Override
                public void run() {
                    if (Objects.world.isLocked()) {
                        runnablePool.add(this);
                        return;
                    } else {
                        RemoveFloorComponent removeFloorComponent = Objects.REMOVE_FLOOR_MAPPER.get(entity);

                        Vector2 tilePosition = removeFloorComponent.playerPosition.cpy()
                                .scl(1f / Values.TILED_SIZE_PIXELS);
                        tilePosition.x = (int) tilePosition.x;
                        tilePosition.y = (int) tilePosition.y;

                        if (AStar.isSolid((int) tilePosition.x, (int) tilePosition.y)) {
                            return;
                        }

                        tilePosition.scl(Values.MAP_SIZE);

                        Entity holeEntity = new Entity();

                        SpriteComponent spriteComponent = new SpriteComponent();
                        spriteComponent.sprite = new Sprite(new Texture(Gdx.files.internal("Hole.png")));
                        spriteComponent.sprite.setPosition(tilePosition.x, tilePosition.y);

                        RemoveEntityTimerComponent removeEntityTimerComponent = new RemoveEntityTimerComponent();
                        removeEntityTimerComponent.time = Values.REMOVE_FLOOR_TIME;

                        //Box2DComponent box2DComponent = Box2DUtils.createCircle(spriteComponent.sprite);

                        HoleComponent holeComponent = new HoleComponent();

                        AshleyUtils.addComponents(entity, removeEntityTimerComponent, spriteComponent,
                                holeComponent);

                        //entity.add(box2DComponent);

                        //box2DComponent.fixture.setUserData(entity);

                        engine.addEntity(holeEntity);
                    }
                }
            });
        }

        @Override
        public void entityRemoved(Entity entity) {
        }

    });

}

From source file:us.notsoserio.ninja.session.client.ClientInputManager.java

License:Apache License

public static void ProcessInput(PlayerBehavior player, ClientSession clientSession) {

    if (Gdx.input.isButtonPressed(Input.Buttons.RIGHT) && !recoil) {
        Vector2 velocity = new Vector2((Gdx.input.getX() - 1280 / 2) / NinjaGame.ZoomFactor,
                ((720 - Gdx.input.getY()) - 720 / 2) / NinjaGame.ZoomFactor);
        velocity.scl(0.4f);
        player.FireProjectile(velocity, Projectiles.Kunai);
        recoil = true;/*ww w  .j  a v  a  2 s .  c om*/
    } else if (!Gdx.input.isButtonPressed(Input.Buttons.RIGHT)) {
        recoil = false;
    }

    if (player.isInControl) {
        if (Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
            player.isWalkingLeft = false;
            player.isWalkingRight = false;
            player.isWalkingUp = false;
            player.isWalkingDown = false;
            player.isJumping = true;
            player.JumpX = (Gdx.input.getX() - 1280 / 2) / NinjaGame.ZoomFactor;
            player.JumpX *= 3f;
            player.JumpY = ((720 - Gdx.input.getY()) - 720 / 2) / NinjaGame.ZoomFactor;
            player.JumpY *= 3f;
        } else if (Gdx.input.isKeyPressed(Input.Keys.A)) {
            player.isWalkingLeft = true;
        } else if (Gdx.input.isKeyPressed(Input.Keys.D)) {
            player.isWalkingRight = true;
        } else if (Gdx.input.isKeyPressed(Input.Keys.W)) {
            player.isWalkingUp = true;
        } else if (Gdx.input.isKeyPressed(Input.Keys.S)) {
            player.isWalkingDown = true;
        } else {
            player.isWalkingLeft = false;
            player.isWalkingRight = false;
            player.isWalkingUp = false;
            player.isWalkingDown = false;
        }
    } else {
        player.isWalkingLeft = false;
        player.isWalkingRight = false;
        player.isWalkingUp = false;
        player.isWalkingDown = false;
    }

    String newCommand = "5;";
    if (Gdx.input.isKeyPressed(Input.Keys.W)) {
        newCommand += "1;";
    } else {
        newCommand += "0;";
    }
    if (Gdx.input.isKeyPressed(Input.Keys.A)) {
        newCommand += "1;";
    } else {
        newCommand += "0;";
    }
    if (Gdx.input.isKeyPressed(Input.Keys.S)) {
        newCommand += "1;";
    } else {
        newCommand += "0;";
    }
    if (Gdx.input.isKeyPressed(Input.Keys.D)) {
        newCommand += "1;";
    } else {
        newCommand += "0;";
    }
    if (Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
        newCommand += "1;";
    } else {
        newCommand += "0;";
    }
    if (Gdx.input.isButtonPressed(Input.Buttons.RIGHT)) {
        newCommand += "1;";
    } else {
        newCommand += "0;";
    }

    clientSession.AddCommand(new Command(CommandType.Input).SetPayload(newCommand));

}