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

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

Introduction

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

Prototype

Vector2 Zero

To view the source code for com.badlogic.gdx.math Vector2 Zero.

Click Source Link

Usage

From source file:Tabox2D.java

License:Open Source License

/**
 * Updates the simulation with the given delta time
 * @param delta The delta time to simulate
 *///ww  w . j a  v a  2 s  .  c  om
public void update(float delta) {
    world.step(delta, 6, 2);
    // Move sprites:
    for (Tabody t : tabodies) {
        if (t.sprite != null) {
            float xb = t.body.getPosition().x * meterSize;
            float yb = t.body.getPosition().y * meterSize;
            xb -= t.sprite.getWidth() / 2;
            yb -= t.sprite.getHeight() / 2;
            t.sprite.setPosition(xb, yb);
            t.sprite.setRotation(t.body.getAngle() * MathUtils.radiansToDegrees);
        }
        // Constant force (using velocity vector):
        if (!t.velocity.equals(Vector2.Zero)) {
            t.body.setLinearVelocity(t.velocity);
        }
    }
}

From source file:ca.hiphiparray.amazingmaze.Player.java

License:Open Source License

/**
 * Set the correct image for the player.
 *
 * @param deltaTime how much time has passed since the last frame.
 *///from w w w  .  ja  v  a2  s .c  om
private void updateImage(float deltaTime) {
    if (!direction.equals(Vector2.Zero)) { // If the mouse if moving, use frame 3.
        stateTime = (Assets.MOUSE_RUN_FRAME - 1) * Assets.MOUSE_FRAME_DURATION;
    } else if (horizontalDir != lastHorizontalDir || verticalDir != lastVerticalDir) {
        stateTime = (Assets.MOUSE_FRAME_COUNT - 1) * Assets.MOUSE_FRAME_DURATION;
    } else {
        stateTime += deltaTime;
    }

    if (verticalDir == VerticalDirection.UP) {
        setRegion(Assets.mouseUp.getKeyFrame(stateTime));
    } else if (verticalDir == VerticalDirection.DOWN) {
        setRegion(Assets.mouseDown.getKeyFrame(stateTime));
    } else if (horizontalDir == HorizontalDirection.LEFT) {
        setRegion(Assets.mouseLeft.getKeyFrame(stateTime));
    } else {
        setRegion(Assets.mouseRight.getKeyFrame(stateTime));
    }
}

From source file:com.dongbat.invasion.buff.effects.Stun.java

@Override
public void update(Entity source, Entity target) {
    PhysicsUtil.setVelocity(target, Vector2.Zero);
}

From source file:com.github.unluckyninja.defenseofhuman.model.entity.Rope.java

License:Open Source License

public Rope(GameWorld gameWorld, Body body, Vector2 direction) {
    this.gameWorld = gameWorld;
    world = body.getWorld();//from www .  j a  va 2  s  . com
    bodyA = body;

    // ???
    Vector2 oriPosition = new Vector2(body.getPosition());
    if (direction.equals(Vector2.Zero)) {
        direction = Vector2.X;
    }
    Vector2 dir = new Vector2(direction);
    dir.nor();
    Vector2 distance = dir.scl(width / 2 * 1.25f); // ,?1/4,?

    // ?body
    bodyDef.angle = (float) Math.toRadians(dir.angle());
    bodyDef.position.set(distance.add(oriPosition));
    bodyDef.linearDamping = 0.3f;
    bodyDef.type = BodyDef.BodyType.DynamicBody;

    Body piece = body.getWorld().createBody(bodyDef);
    piece.setGravityScale(0.1f);

    // ?
    // ??,????
    fixtureDef.isSensor = true;
    fixtureDef.density = 0.001f;

    polygonShape.setAsBox(width / 2, height / 2);

    fixtureDef.shape = polygonShape;

    piece.createFixture(fixtureDef);

    // ?
    RevoluteJointDef rjDef = new RevoluteJointDef();
    rjDef.bodyA = body;
    rjDef.bodyB = piece;

    rjDef.localAnchorA.x = 0;
    rjDef.localAnchorA.y = 0;
    rjDef.localAnchorB.x = -width / 2 * 1.25f;
    rjDef.localAnchorB.y = 0;

    joints.add(body.getWorld().createJoint(rjDef));
    pieces.add(piece);

    piece.setUserData(this);

}

From source file:com.github.unluckyninja.defenseofhuman.model.entity.Rope.java

License:Open Source License

private Rope append(Vector2 direction) {
    //TODO /*from   w w  w. j  a va 2  s  . co m*/
    Body body = pieces.get(pieces.size - 1);

    // ???
    oriPosition.set(body.getWorldPoint(temp1.set(width / 2 * 1.25f, 0)));
    if (direction.equals(Vector2.Zero)) {
        direction = Vector2.X;
    }
    dir.set(direction);
    dir.nor();
    dir.scl(width / 2 * 1.25f);

    // ?body
    bodyDef.angle = (float) Math.toRadians(dir.angle());
    bodyDef.position.set(dir.add(oriPosition));

    Body piece = body.getWorld().createBody(bodyDef);
    piece.setGravityScale(0.1f);

    // ?
    fixtureDef.isSensor = true;
    fixtureDef.density = 0.001f;

    polygonShape.setAsBox(width / 2, height / 2);

    fixtureDef.shape = polygonShape;

    piece.createFixture(fixtureDef);

    // ??
    RevoluteJointDef rjDef = new RevoluteJointDef();
    rjDef.bodyA = body;
    rjDef.bodyB = piece;

    rjDef.localAnchorA.x = width / 2 * 1.25f;
    rjDef.localAnchorA.y = 0;
    rjDef.localAnchorB.x = -width / 2 * 1.25f;
    rjDef.localAnchorB.y = 0;

    joints.add(body.getWorld().createJoint(rjDef));
    pieces.add(piece);

    body.setUserData(this);

    return this;
}

From source file:com.kotcrab.vis.ui.widget.Draggable.java

License:Apache License

private void getStageCoordinatesWithDeadzone(final InputEvent event) {
    final Actor parent = mimic.getActor().getParent();
    if (parent != null) {
        MIMIC_COORDINATES.set(Vector2.Zero);
        parent.localToStageCoordinates(MIMIC_COORDINATES);
        final float parentX = MIMIC_COORDINATES.x;
        final float parentY = MIMIC_COORDINATES.y;
        final float parentEndX = parentX + parent.getWidth();
        final float parentEndY = parentY + parent.getHeight();
        if (isWithinDeadzone(event, parentX, parentY, parentEndX, parentEndY)) {
            // Keeping within parent bounds:
            MIMIC_COORDINATES.set(event.getStageX() + offsetX, event.getStageY() + offsetY);
            if (MIMIC_COORDINATES.x < parentX) {
                MIMIC_COORDINATES.x = parentX;
            } else if (MIMIC_COORDINATES.x + mimic.getWidth() > parentEndX) {
                MIMIC_COORDINATES.x = parentEndX - mimic.getWidth();
            }/*from  w w w  .j a v a 2  s.c om*/
            if (MIMIC_COORDINATES.y < parentY) {
                MIMIC_COORDINATES.y = parentY;
            } else if (MIMIC_COORDINATES.y + mimic.getHeight() > parentEndY) {
                MIMIC_COORDINATES.y = parentEndY - mimic.getHeight();
            }
            STAGE_COORDINATES.set(MathUtils.clamp(event.getStageX(), parentX, parentEndX - 1f),
                    MathUtils.clamp(event.getStageY(), parentY, parentEndY - 1f));
        } else {
            getStageCoordinatesWithOffset(event);
        }
    } else {
        getStageCoordinatesWithOffset(event);
    }
}

From source file:com.kotcrab.vis.ui.widget.Draggable.java

License:Apache License

private void getStageCoordinatesWithinParent(final InputEvent event) {
    final Actor parent = mimic.getActor().getParent();
    if (parent != null) {
        MIMIC_COORDINATES.set(Vector2.Zero);
        parent.localToStageCoordinates(MIMIC_COORDINATES);
        final float parentX = MIMIC_COORDINATES.x;
        final float parentY = MIMIC_COORDINATES.y;
        final float parentEndX = parentX + parent.getWidth();
        final float parentEndY = parentY + parent.getHeight();
        MIMIC_COORDINATES.set(event.getStageX() + offsetX, event.getStageY() + offsetY);
        if (MIMIC_COORDINATES.x < parentX) {
            MIMIC_COORDINATES.x = parentX;
        } else if (MIMIC_COORDINATES.x + mimic.getWidth() > parentEndX) {
            MIMIC_COORDINATES.x = parentEndX - mimic.getWidth();
        }//  w  w  w .ja va  2 s  .  c om
        if (MIMIC_COORDINATES.y < parentY) {
            MIMIC_COORDINATES.y = parentY;
        } else if (MIMIC_COORDINATES.y + mimic.getHeight() > parentEndY) {
            MIMIC_COORDINATES.y = parentEndY - mimic.getHeight();
        }
        STAGE_COORDINATES.set(MathUtils.clamp(event.getStageX(), parentX, parentEndX - 1f),
                MathUtils.clamp(event.getStageY(), parentY, parentEndY - 1f));
    } else {
        getStageCoordinatesWithOffset(event);
    }
}

From source file:com.mcprog.ragnar.screens.GameScreen.java

License:Apache License

/**
 * Called when this screen is focused on
 * Renews physics objects/*  w w  w  .j  a va  2 s .com*/
 * Renews input
 * Mobile unlocks play for the 1st time achievement
 */
@Override
public void show() {
    inputMultiplexer.clear();
    timeInGame = 0;
    world = new World(Vector2.Zero, true);
    player = new Player(world, Vector2.Zero, camera, this);
    player.init();
    spawner = new ArrowSpawner(world, player);
    bounds = new Bounds(world, Gdx.graphics.getWidth() / 8);

    world.setContactListener(this);
    if (Ragnar.debugger.on) {
        stage.setDebugAll(true);
    }
    gamePaused = false;
    pauseTable.show();
    inputMultiplexer.addProcessor(stage);
    inputMultiplexer.addProcessor(player);
    Gdx.input.setInputProcessor(inputMultiplexer);
    if (Ragnar.isMobile) {
        game.gpgs.unlockAchievement(1);
        //game.adRefresher.hideBanner();
    }
}

From source file:com.mcprog.ragnar.screens.WinScreen.java

License:Apache License

/**
 * Called when screen is shown<br>
 * Instantiates each meteor<br>//w  w w .j a va 2  s  .  c om
 * Renews world and physics<br>
 * Unlocks win achievement and submits highscore
 */
@Override
public void show() {
    world = new World(new Vector2(0, -9.81f), true);
    for (int i = 0; i < meteors.length; ++i) {
        meteors[i] = new Meteor(world);
    }
    angel = new Angel(world, Vector2.Zero, camera);
    leftSidebar = new Sprite(new Texture(Gdx.files.internal("heaven_sidebar.png")));
    rightSidebar = new Sprite(new Texture(Gdx.files.internal("heaven_sidebar.png")));
    fontBatch = new SpriteBatch();
    Gdx.input.setCatchBackKey(true);
    if (Ragnar.isMobile) {
        game.gpgs.unlockAchievement(4);
    }
    if (Ragnar.isMobile) {
        game.gpgs.submitHighscore((int) game.gameScreen.timeInGame);
    }
    Gdx.input.setInputProcessor(angel);
}

From source file:com.mygdx.game.Sprites.Boss.Boss.java

private void defineBoss() {

    BodyDef bdef = new BodyDef();

    bdef.position.set(getX(), getY());//from ww w  .j av  a2  s  .co  m
    bdef.type = BodyDef.BodyType.DynamicBody;
    b2body = world.createBody(bdef);

    FixtureDef fdef = new FixtureDef();

    PolygonShape shape = new PolygonShape();

    shape.setAsBox(25 / AdventureGame.PPM, 20 / AdventureGame.PPM);

    fdef.isSensor = true;
    fdef.shape = shape;
    fdef.friction = 0;
    fdef.filter.categoryBits = AdventureGame.BOSS_BIT;

    fdef.filter.maskBits = AdventureGame.BULLET_BIT | AdventureGame.PLAYER_BIT | AdventureGame.DYNAMITE_BIT
            | AdventureGame.GROUND_BIT | AdventureGame.FLOOR_BIT;

    b2body.createFixture(fdef).setUserData(this);

    fdef.isSensor = false;
    EdgeShape downShape = new EdgeShape();
    downShape.set(-51 / AdventureGame.PPM, -22 / AdventureGame.PPM, 51 / AdventureGame.PPM,
            -22 / AdventureGame.PPM);
    fdef.shape = downShape;
    b2body.createFixture(fdef).setUserData(this);

    b2body.setLinearVelocity(Vector2.Zero);
    stand = true;
}