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

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

Introduction

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

Prototype

public Vector2() 

Source Link

Document

Constructs a new vector at (0,0)

Usage

From source file:AITest.Box2DSteeringEntity.java

public Box2DSteeringEntity(Body body, float boundingRadius) {
    this.body = body;
    this.boundingRadius = boundingRadius;
    this.maxAngularAcceleration = 5;
    this.maxAngularSpeed = 5;
    this.maxLinearSpeed = 5;
    this.maxLinearAcceleration = 500;
    this.tagged = false;
    this.steeringOutput = new SteeringAcceleration<Vector2>(new Vector2());
    this.body.setUserData(this);
}

From source file:AITest.Box2DSteeringEntity.java

@Override
public Vector2 newVector() {
    return new Vector2();
}

From source file:app.badlogicgames.superjumper.DynamicGameObject.java

License:Apache License

public DynamicGameObject(float x, float y, float width, float height) {
    super(x, y, width, height);
    velocity = new Vector2();
    accel = new Vector2();
}

From source file:at.therefactory.jewelthief.jewels.Jewel.java

License:Open Source License

Jewel(String spriteId) {
    position = new Vector2();
    sprite = JewelThief.getInstance().getTextureAtlas().createSprite(spriteId);

    // initially hidden from visible screen
    setPosition(-100, -100);//from w w w  . j ava 2  s  .c  o m
    sprite.setPosition(-100, -100);
}

From source file:be.ac.ucl.lfsab1509.bouboule.game.body.GameBody.java

License:Open Source License

/**
 * Default constructor that set the object to living and initialise.
 * the position vector
 * 
 * GameBody()
 */
public GameBody() {

    positionVector = new Vector2();
}

From source file:be.ac.ucl.lfsab1509.bouboule.game.physicEditor.BodyEditorLoader.java

License:Open Source License

private Vector2 newVec() {
    return vectorPool.isEmpty() ? new Vector2() : vectorPool.remove(0);
}

From source file:br.cefetmg.games.minigames.FleeTheTartarus.java

private void spawnEnemy() {

    Vector2 tartarusPosition = new Vector2();

    boolean appearFromSides = MathUtils.randomBoolean();
    if (appearFromSides) {
        boolean appearFromLeft = MathUtils.randomBoolean();
        if (appearFromLeft) {
            tartarusPosition.x = 0;//from  w w  w.j  a  v a  2 s.c o m
            tartarusPosition.y = MathUtils.random(Config.WORLD_HEIGHT);
        } else {
            tartarusPosition.x = Gdx.graphics.getWidth();
            tartarusPosition.y = MathUtils.random(Config.WORLD_HEIGHT);
        }
    } else {
        boolean appearFromBottom = MathUtils.randomBoolean();
        if (appearFromBottom) {
            tartarusPosition.y = 0;
            tartarusPosition.x = MathUtils.random(Config.WORLD_WIDTH);
        } else {
            tartarusPosition.y = Gdx.graphics.getHeight();
            tartarusPosition.x = MathUtils.random(Config.WORLD_WIDTH);
        }
    }

    Vector2 obj = new Vector2(tooth.getToothPosition());

    Vector2 tartarusSpeed = obj.sub(tartarusPosition).nor().scl(2 * this.maximumEnemySpeed);

    Tartarus enemy = new Tartarus(tartarusTexture);
    enemy.setPosition(tartarusPosition.x, tartarusPosition.y);
    enemy.setSpeed(tartarusSpeed);
    enemy.setScale(0.7f);
    enemies.add(enemy);

    tartarusAppearingSound.random().play(); //toca sempre a mesma musica

}

From source file:br.cefetmg.games.minigames.SaveTheTeeth.java

private void throwFood() {
    Vector2 foodPos = new Vector2();
    Vector2 fSpeed;//w ww.  j  a va 2 s  .co m
    Vector2 goalCenter = new Vector2();
    Vector2 goal = this.mouth.getBoundingRectangle().getCenter(goalCenter);
    float xOffset;
    float yOffset;
    boolean isGood = MathUtils.randomBoolean();
    TextureRegion fTexture;
    Random rand = new Random();

    if (isGood) {
        xOffset = Food.GOOD_WIDTH;
        yOffset = Food.GOOD_HEIGHT;
        fTexture = GoodFoodTextures[0][rand.nextInt(2)];
    } else {
        xOffset = Food.BAD_WIDTH;
        yOffset = Food.BAD_HEIGHT;
        fTexture = BadFoodTextures[0][rand.nextInt(2)];
    }

    if (MathUtils.randomBoolean()) {
        foodPos.x = MathUtils.randomBoolean() ? -xOffset : super.screen.viewport.getWorldWidth();
        foodPos.y = MathUtils.random(-yOffset, super.screen.viewport.getWorldHeight());
    } else {
        foodPos.y = MathUtils.randomBoolean() ? -yOffset : super.screen.viewport.getWorldHeight();
        foodPos.x = MathUtils.random(-xOffset, super.screen.viewport.getWorldWidth());
    }

    //fSpeed=new Vector2(goalCenter.x,goalCenter.y);
    //fSpeed.nor().scl(this.foodSpeed);
    fSpeed = goal.sub(foodPos).nor().scl(this.foodSpeed);

    Food f = new Food(fTexture, isGood);
    f.setSpeed(fSpeed);
    f.setPosition(foodPos.x, foodPos.y);
    food.add(f);
}

From source file:broken.shotgun.throwthemoon.stages.GameStage.java

License:Open Source License

public GameStage(final AssetManager manager) {
    super(new StretchViewport(WIDTH, HEIGHT));

    this.manager = manager;

    loadLevel();/*from  w ww .j  ava 2  s.  c  om*/

    loadSounds();

    loadFont();

    random = new Random(System.currentTimeMillis());
    fadingOut = false;

    background = new Background(manager);
    chain = new MoonChain(manager);
    player = new Player(manager);
    moon = new Moon(manager);

    moonImpactMeter = new MoonImpactMeter(moon);

    screenFadeActor = new Actor();
    screenFadeActor.setBounds(0, 0, WIDTH, HEIGHT);
    screenFadeActor.setColor(Color.CLEAR);

    levelDebugRenderer = new LevelDebugRenderer();
    screenLogger = new StringBuilder();

    uiBatch = new SpriteBatch();
    renderer = new ShapeRenderer();
    renderer.setAutoShapeType(true);

    touchPoint = new Vector2();

    resetLevel();

    debug = isDebug();
    setDebugAll(debug);

    Gdx.input.setInputProcessor(this);

    addListener(new ActorGestureListener() {
        @Override
        public void touchDown(InputEvent event, float x, float y, int pointer, int button) {
            if (pointer == 0 && !(event.getTarget() instanceof Enemy || event.getTarget() instanceof Boss
                    || (boss != null && event.getTarget() instanceof MoonChain))) {
                player.moveTo(touchPoint.set(x, y));
            }

            // FIXME replace String.format with StringBuilder for HTML
            if (isDebug())
                Gdx.app.log("GameStage", String.format("touchDown %s %s", event.getType().toString(),
                        event.getTarget().toString()));
            super.touchDown(event, x, y, pointer, button);
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            if (pointer == 0 && player.isWalking()) {
                player.stop();
            }
            super.touchUp(event, x, y, pointer, button);
        }

        @Override
        public void pan(InputEvent event, float x, float y, float deltaX, float deltaY) {
            if (boss == null || (boss != null && !(event.getTarget() instanceof MoonChain))) {
                player.moveTo(touchPoint.set(x, y));
            }

            super.pan(event, x, y, deltaX, deltaY);
        }

        @Override
        public void tap(InputEvent event, float x, float y, int count, int button) {
            player.performAttack(count);

            float deltaX = ((player.getX() + player.getOriginX()) - x);
            player.setFlipX(deltaX > 0);

            // FIXME replace String.format with StringBuilder for HTML
            if (isDebug()) {
                Actor target = event.getTarget();
                Gdx.app.log("GameStage",
                        String.format("tap type:%s target:%s [target x=%.2f y=%.2f] count:%d [x:%.2f, y:%.2f]",
                                event.getType().toString(), target.toString(), target.getX(), target.getY(),
                                count, x, y));
            }
            super.tap(event, x, y, count, button);
        }

        @Override
        public void fling(InputEvent event, float velocityX, float velocityY, int button) {
            Gdx.app.log("GameStage",
                    String.format("fling velocityX:%.2f velocityY:%.2f", velocityX, velocityY));
            if (player.isMoonThrowEnabled() && velocityY < 0 && chain.isAttached()
                    && event.getTarget() instanceof MoonChain) {
                int multiplier = (boss != null && boss.isDefeated()) ? 10 : 2;
                moon.addDistance(velocityY * multiplier);
                chain.animatePull();
            }
            super.fling(event, velocityX, velocityY, button);
        }

    });

    addListener(new InputListener() {
        int attackCounter = 0;

        @Override
        public boolean keyDown(InputEvent event, int keycode) {
            switch (keycode) {
            case Input.Keys.D:
                if (debug && player.isMoonThrowEnabled() && !moon.isFalling()) {
                    moon.startFalling();
                }
                break;
            case Input.Keys.K:
                if (debug) {
                    clearAllEnemies();
                }
                break;
            case Input.Keys.SPACE:
                attackCounter++;
                player.performAttack(attackCounter);
                return true;
            case Input.Keys.LEFT:
                player.velocity.x = -7;
                player.startWalkState();
                return true;
            case Input.Keys.RIGHT:
                player.velocity.x = 7;
                player.startWalkState();
                return true;
            case Input.Keys.UP:
                player.velocity.y = 7;
                player.startWalkState();
                return true;
            case Input.Keys.DOWN:
                player.velocity.y = -7;
                player.startWalkState();
                return true;
            }

            return super.keyDown(event, keycode);
        }

        @Override
        public boolean keyUp(InputEvent event, int keycode) {
            switch (keycode) {
            case Input.Keys.LEFT:
            case Input.Keys.RIGHT:
                player.velocity.x = 0;
                return true;
            case Input.Keys.UP:
            case Input.Keys.DOWN:
                player.velocity.y = 0;
                return true;
            }
            return super.keyUp(event, keycode);
        }
    });
}

From source file:broken.shotgun.throwthemoon.stages.GameStage.java

License:Open Source License

public void spawnEnemies(List<EnemySpawn> spawnList) {
    int offsetY = 100;
    for (EnemySpawn spawn : spawnList) {
        if (spawn.enemyId == 0) {
            Enemy newEnemy = new Enemy(manager);
            Vector2 spawnPoint = new Vector2();
            spawnPoint.y = offsetY + (getViewport().getScreenHeight() / spawnList.size());
            switch (spawn.location) {
            case FRONT:
                spawnPoint.x = getViewport().getScreenWidth() * 0.8f;
                break;
            case BACK:
                spawnPoint.x = getViewport().getScreenWidth() * 0.15f;
                break;
            }//  www.  j a v  a2 s .c o  m

            screenToStageCoordinates(spawnPoint);
            newEnemy.setPosition(spawnPoint.x, spawnPoint.y + (newEnemy.getHeight() / 2));
            newEnemy.setColor(1.0f, 1.0f, 1.0f, 0.0f);
            newEnemy.addAction(Actions.fadeIn(0.5f));
            addActor(newEnemy);
            offsetY += (getViewport().getScreenHeight() / spawnList.size());
        } else if (spawn.enemyId == 100) {
            boss = new Boss(manager);
            Vector2 spawnPoint = new Vector2();
            spawnPoint.y = (getViewport().getScreenHeight() / 2);
            switch (spawn.location) {
            case FRONT:
                spawnPoint.x = getViewport().getScreenWidth() * 0.7f;
                break;
            case BACK:
                spawnPoint.x = getViewport().getScreenWidth() * 0.15f;
                break;
            }

            screenToStageCoordinates(spawnPoint);
            boss.setPosition(spawnPoint.x + (getViewport().getScreenWidth() * 0.5f),
                    spawnPoint.y - (boss.getHeight() / 2));
            boss.addAction(Actions.sequence(
                    Actions.moveTo(spawnPoint.x, spawnPoint.y - (boss.getHeight() / 2), 3f, Interpolation.fade),
                    Actions.run(new Runnable() {
                        @Override
                        public void run() {
                            boss.startBattle();
                        }
                    })));
            addActor(boss);
            player.enableMoonThrow();
            chain.hintPullChain();
        }
    }
}