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(float x, float y) 

Source Link

Document

Constructs a vector with the given components

Usage

From source file:com.dongbat.game.buff.effects.ProduceFoodSchedule.java

@Override
public void update(World world, Entity source, Entity target) {
    long currentFrame = TimeUtil.getCurrentFrame(world);
    float elapsed = currentFrame - lastRest;

    if (!resting && elapsed > overheatFrame) {
        lastRest = currentFrame;/*from  ww w  .j av a2s  .c o m*/
        resting = true;
    }

    if (resting && elapsed > overheatFrame + cooldownFrame) {
        resting = false;
    }

    if (resting) {
        return;
    }

    if (ECSUtil.getFrame(world) % scheduleFrame == 0) {
        Vector2 position = PhysicsUtil.getPosition(world, target);

        UnitMovement unitMovement = EntityUtil.getComponent(world, source, UnitMovement.class);
        Vector2 destination = unitMovement.getDirectionVelocity();
        float degree = 60;

        for (int i = 0; i < 1; i++) {
            float d = ECSUtil.getRandom(world).getFloat(-degree / 2, degree / 2);
            Vector2 direction = destination.cpy().scl(-1).nor().rotate(d);
            if (direction.cpy().nor().len2() == 0) {
                //TODO: fixxxxxxxxxxxxx this
                direction = new Vector2(ECSUtil.getRandom(world).getFloat(-1, 1),
                        ECSUtil.getRandom(world).getFloat(-1, 1));
            }
            Entity food = EntityFactory.createFood(world, position, UuidUtil.getUuid(source));
            // TODO: food expiring system
            BuffUtil.addBuff(world, source, food, "ToBeRemoved", 3000, 1);
            BuffUtil.addBuff(world, source, food, "ToxicFood", 400, 1);
            BuffUtil.addBuff(world, source, food, "Forced",
                    (int) (600 * ECSUtil.getRandom(world).getFloat(0.5f, 1.25f)), 1, "forceStrength", 0.75f,
                    "direction", direction);
        }
    }
}

From source file:com.dongbat.game.buff.effects.RandomDestinationSchedule.java

@Override
public void durationStart(World world, Entity source, Entity target) {
    UnitMovement unitComponent = EntityUtil.getComponent(world, target, UnitMovement.class);
    float posX = (float) (ECSUtil.getRandom(world).getFloat(-1, 1) * scaleX);
    float posY = (float) (ECSUtil.getRandom(world).getFloat(-1, 1) * scaleY);
    Vector2 position = PhysicsUtil.getPosition(world, target);
    Vector2 destination = (new Vector2(posX, posY)).cpy().sub(position.cpy());
    unitComponent.setDirectionVelocity(destination.cpy().nor());
}

From source file:com.dongbat.game.buff.effects.Respawn.java

@Override
public void durationEnd(World world, Entity source, Entity target) {
    EntityUtil.getComponent(world, target, Stats.class).setAllowComsumming(true);
    EntityUtil.getComponent(world, target, Stats.class).setConsumable(true);
    EntityUtil.getComponent(world, target, UnitMovement.class).setDisabled(false);

    PhysicsUtil.setRadius(target.getWorld(), target, minRadius);
    Vector2 randomPos = new Vector2(
            ECSUtil.getRandom(world).getFloat(-Constants.GAME.FRAME_WIDTH / 2, Constants.GAME.FRAME_WIDTH / 2),
            ECSUtil.getRandom(world).getFloat(-Constants.GAME.FRAME_HEIGHT / 2,
                    Constants.GAME.FRAME_HEIGHT / 2));
    if (position == null) {
        position = randomPos;/* w ww  .j a  v  a 2 s .  c  o  m*/
    }
    PhysicsUtil.setPosition(target.getWorld(), target, position);
}

From source file:com.dongbat.game.screen.BotGameScreen.java

public BotGameScreen() {
    WorldConfiguration config = ECSUtil.initWorldConfig();
    world = new World(config);
    UnitRegistry.load();/*  ww  w .  ja  va  2 s. c  o  m*/
    BuffRegistry.load();
    AbilityRegistry.load();
    ECSUtil.init(world);
    PhysicsUtil.init(world);
    Entity localPlayer = EntityFactory.createPlayer(world, new Vector2(-60, -60), "phong");
    BuffUtil.addBuff(world, localPlayer, localPlayer, "FeedSmaller", -1, 1);
    LocalPlayerUtil.setLocalPlayer(UuidUtil.getUuid(localPlayer));
    LocalPlayerUtil.setLocalWorld(world);

    UnitFactory.createQueen(world, new Vector2(0, 20), 10);
    UnitFactory.createUnit(world, "minh", new Vector2(60, 60));
    UnitFactory.createUnit(world, "minh", new Vector2(-60, 60));
    UnitFactory.createUnit(world, "phong", new Vector2(60, -60));
}

From source file:com.dongbat.game.screen.DynamicMenuScreen.java

public DynamicMenuScreen() {
    stage = new Stage();
    InputUtil.addProcessor(stage, 0);/*from  w ww . j av  a2  s .  com*/
    stage.setViewport(new ExtendViewport(800, 480));
    stage.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
    buttonSinglePlayer = new ImageButton(new SpriteDrawable(new Sprite(AssetUtil.singleButton)),
            new SpriteDrawable(new Sprite(AssetUtil.pressedSingleButton)));
    buttonSinglePlayer.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            ScreenUtil.setScreen(new GameScreen());
        }
    });
    buttonSinglePlayer.setSize(270, 62);
    buttonSinglePlayer.setPosition(-135, -90);

    buttonMultiPlayer = new ImageButton(new SpriteDrawable(new Sprite(AssetUtil.multiButton)));
    buttonMultiPlayer.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
        }
    });
    buttonMultiPlayer.setDisabled(true);

    buttonMultiPlayer.setSize(270, 62);
    buttonMultiPlayer.setPosition(-135, -180);

    title = new Image(new SpriteDrawable(new Sprite(AssetUtil.title)));
    title.setSize(230, 100);
    title.setPosition(-115, 60);

    stage.addActor(title);
    stage.addActor(buttonSinglePlayer);
    stage.addActor(buttonMultiPlayer);

    WorldConfiguration config = new WorldConfiguration();
    config.setSystem(new Box2dSystem(2), false);
    config.setSystem(new AiControlledSystem(5), false);
    config.setSystem(new BuffSystem(), false);
    config.setSystem(new DetectionCleanupSystem(1), false);
    config.setSystem(new DetectionSystem(1), false);
    config.setSystem(new ConsumingSystem(), false);
    config.setSystem(new InputProcessorSystem(), false);
    config.setSystem(new MovementSystem(), false);
    config.setSystem(new SpriteRenderSystem(), true);
    config.setSystem(new GridRendererSystem(), true);
    config.setSystem(new ParallaxBackgroundSystem(), true);
    config.setSystem(new DisplayUpdateSystem(), true);
    config.setSystem(new FoodAnimationSystem(), true);
    config.setSystem(new AnimationRenderSystem(), true);
    //    config.setSystem(new Shaperenderer1(), true);

    config.setManager(new UuidEntityManager());

    world = new World(config);
    UnitRegistry.load();
    BuffRegistry.load();
    AbilityRegistry.load();
    ECSUtil.init(world);
    worldProgress = new WorldProgress(0.015f);
    worldProgressMap.put(world, worldProgress);

    world.getSystem(DetectionSystem.class).setModifier(3);

    PhysicsUtil.init(world);

    PhysicsCameraUtil.getCamera().zoom = 5;
    PhysicsCameraUtil.getCamera().position.set(new Vector2(80, -70), 0);
    PhysicsCameraUtil.getCamera().update();

    Entity queen = UnitFactory.createQueen(world, new Vector2(100, -80), 8);
    BuffComponent queenBuff = EntityUtil.getComponent(world, queen, BuffComponent.class);

    queenBuff.getBuffs().remove("QueenTeleportSchedule");
    queenBuff.getBuffs().remove("SelfDefense");
    queenBuff.getBuffs().remove("FeedSmaller");
    queenBuff.getBuffs().remove("ProduceFoodSchedule");
    BuffUtil.addBuff(world, queen, queen, "SelfDefense", -1, 1, "framePerFood", 15);
    UnitMovement queenMove = EntityUtil.getComponent(world, queen, UnitMovement.class);
    queenMove.setDirectionVelocity(new Vector2());
    //    PhysicsUtil.setPosition(world, queen, new Vector2(500, -500));

    Entity createUnit = UnitFactory.createUnit(world, "bao", new Vector2(0, 30));
    PhysicsUtil.setRadius(world, createUnit, 1);

    UnitFactory.createUnit(world, "bao", new Vector2(10, 30));
    UnitFactory.createUnit(world, "bao", new Vector2(100, 100));
    UnitFactory.createUnit(world, "bao", new Vector2(50, -40));
    //    UnitFactory.createUnit(world, "bao", new Vector2(30, 30));
    //    UnitFactory.createUnit(world, "bao", new Vector2(0, -30));
    //    UnitFactory.createUnit(world, "bao", new Vector2(-10, -30));
    //    UnitFactory.createUnit(world, "bao", new Vector2(-20, -30));
}

From source file:com.dongbat.game.screen.GameScreen.java

public GameScreen() {
    AdUtil.hideAd();/*from   ww w. j  ava 2  s  . c o m*/
    world = ECSUtil.createWorld();
    UnitRegistry.load();
    BuffRegistry.load();
    AbilityRegistry.load();
    ECSUtil.init(world);
    PhysicsUtil.init(world);
    Entity localPlayer = EntityFactory.createPlayer(world, new Vector2(0, 80), "phong");
    //    BuffUtil.addBuff(world, localPlayer, localPlayer, "AttractFood", -1, 1);
    BuffUtil.addBuff(world, localPlayer, localPlayer, "FeedSmaller", -1, 1);
    LocalPlayerUtil.setLocalPlayer(UuidUtil.getUuid(localPlayer));
    LocalPlayerUtil.setLocalWorld(world);

    UnitFactory.createQueen(world, new Vector2(0, 20), 20);
    // UnitFactory.createQueen(world, new Vector2(0, 20), 20);

    GameUtil.addGame(world);
    UnitFactory.createUnit(world, "phong", new Vector2(10, 60));
    UnitFactory.createUnit(world, "bao", new Vector2(10, -60));
    UnitFactory.createUnit(world, "phong", new Vector2(100, -60));
}

From source file:com.dongbat.game.screen.MenuScreen.java

public MenuScreen() {
    AdUtil.showAd();/*from   w  ww .  j a  va2s  .c o m*/
    stage = new Stage();
    InputUtil.addProcessor(stage, 0);
    stage.setViewport(new ExtendViewport(800, 480));
    stage.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
    buttonSinglePlayer = new ImageButton(new SpriteDrawable(new Sprite(AssetUtil.singleButton)),
            new SpriteDrawable(new Sprite(AssetUtil.pressedSingleButton)));
    buttonSinglePlayer.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            ScreenUtil.setScreen(new GameScreen());
        }
    });
    buttonSinglePlayer.setSize(270, 62);
    buttonSinglePlayer.setPosition(-135, -50);

    buttonMultiPlayer = new ImageButton(new SpriteDrawable(new Sprite(AssetUtil.multiButton)));
    buttonMultiPlayer.setDisabled(true);

    buttonMultiPlayer.setSize(270, 62);
    buttonMultiPlayer.setPosition(-135, -130);

    buttonStory = new ImageButton(new SpriteDrawable(new Sprite(AssetUtil.storyButton)));
    buttonStory.setDisabled(true);

    buttonStory.setSize(270, 62);
    buttonStory.setPosition(-135, -210);

    title = new Image(new SpriteDrawable(new Sprite(AssetUtil.title)));
    title.setSize(230, 100);
    title.setPosition(-115, 60);

    stage.addActor(title);
    stage.addActor(buttonSinglePlayer);
    stage.addActor(buttonMultiPlayer);
    stage.addActor(buttonStory);

    WorldConfiguration config = new WorldConfiguration();
    config.setSystem(new Box2dSystem(2), false);
    config.setSystem(new AiControlledSystem(5), false);
    config.setSystem(new BuffSystem(), false);
    config.setSystem(new DetectionCleanupSystem(1), false);
    config.setSystem(new DetectionSystem(1), false);
    config.setSystem(new ConsumingSystem(), false);
    config.setSystem(new InputProcessorSystem(), false);
    config.setSystem(new MovementSystem(), false);
    config.setSystem(new GridRendererSystem(), true);
    config.setSystem(new ParallaxBackgroundSystem(), true);
    config.setSystem(new DisplayUpdateSystem(), true);
    config.setSystem(new FoodAnimationSystem(), true);
    config.setSystem(new AnimationRenderSystem(), true);
    //    config.setSystem(new Shaperenderer1(), true);

    config.setManager(new UuidEntityManager());

    world = new World(config);
    UnitRegistry.load();
    BuffRegistry.load();
    AbilityRegistry.load();
    ECSUtil.init(world);
    worldProgress = new WorldProgress(0.015f);
    worldProgressMap.put(world, worldProgress);

    world.getSystem(DetectionSystem.class).setModifier(3);

    PhysicsUtil.init(world);

    PhysicsCameraUtil.getCamera().zoom = 5;
    PhysicsCameraUtil.getCamera().position.set(new Vector2(80, -70), 0);
    PhysicsCameraUtil.getCamera().update();

    Entity queen = UnitFactory.createQueen(world, new Vector2(100, -80), 15);
    BuffComponent queenBuff = EntityUtil.getComponent(world, queen, BuffComponent.class);

    queenBuff.getBuffs().remove("QueenTeleportSchedule");
    queenBuff.getBuffs().remove("SelfDefense");
    queenBuff.getBuffs().remove("FeedSmaller");
    queenBuff.getBuffs().remove("ProduceFoodSchedule");
    queenBuff.getBuffs().remove("QueenGrowth");
    BuffUtil.addBuff(world, queen, queen, "SelfDefense", -1, 1, "framePerFood", 15);
    UnitMovement queenMove = EntityUtil.getComponent(world, queen, UnitMovement.class);
    queenMove.setDirectionVelocity(new Vector2());
    //    PhysicsUtil.setPosition(world, queen, new Vector2(500, -500));

    Entity createUnit = UnitFactory.createUnit(world, "bao", new Vector2(0, 30));
    PhysicsUtil.setRadius(world, createUnit, 1);

    UnitFactory.createUnit(world, "bao", new Vector2(10, 30));
    UnitFactory.createUnit(world, "bao", new Vector2(100, 100));
    UnitFactory.createUnit(world, "bao", new Vector2(50, -40));
    //    UnitFactory.createUnit(world, "bao", new Vector2(30, 30));
    //    UnitFactory.createUnit(world, "bao", new Vector2(0, -30));
    //    UnitFactory.createUnit(world, "bao", new Vector2(-10, -30));
    //    UnitFactory.createUnit(world, "bao", new Vector2(-20, -30));
}

From source file:com.dongbat.game.system.BorderlandSystem.java

@Override
protected void process(Entity e) {
    Physics physics = EntityUtil.getComponent(world, e, Physics.class);
    UnitMovement movement = EntityUtil.getComponent(world, e, UnitMovement.class);
    Vector2 pos = physics.getBody().getPosition();
    float radius = PhysicsUtil.getRadius(world, e);
    if (radius < 0.5f) {
        radius = 0.5f;/*  ww w .ja v a2s .  co m*/
    }
    if (movement == null) {
        return;
    }

    if (BuffUtil.hasBuff(world, e, "WallForced")) {
        return;
    }

    float x = 0;
    float y = 0;

    if (pos.x > scaleX) {
        x = -1;
    }

    if (pos.x < -scaleX) {
        x = 1;
    }

    if (pos.y < -scaleY) {
        y = 1;
    }

    if (pos.y > scaleY) {
        y = -1;
    }

    if (x != 0 || y != 0) {
        BuffUtil.addBuff(world, e, e, "WallForced", 500, 1, "forceStrength", radius, "direction",
                new Vector2(x, y));
    }
}

From source file:com.dongbat.game.system.GameStageSystem.java

@Override
protected void processSystem() {
    stage.act();//from   ww w. j a  v  a  2 s.  c  o  m

    if (GameUtil.isOver(world) && !ended) {
        ended = true;
        gameEndedWindow = new GameEndedWindow(skin);
        gameEndedWindow.setSize(stage.getWidth(), stage.getHeight());
        stage.addActor(gameEndedWindow);
        world.getSystem(LocalInputSystem.class).setEnabled(false);
        world.getSystem(Box2dSystem.class).setEnabled(false);

        return;
    }
    if (touchpad.isTouched()) {
        float x = touchpad.getKnobPercentX();
        float y = touchpad.getKnobPercentY();

        UUID localPlayerId = LocalPlayerUtil.getLocalPlayer();
        Entity e = UuidUtil.getEntityByUuid(world, localPlayerId);
        if (e == null || localPlayerId == null) {
            return;
        }
        UnitMovement move = EntityUtil.getComponent(world, e, UnitMovement.class);
        move.setDirectionVelocity(new Vector2(x, y));
    }

    //    if (WorldQueryUtil.getAllQueen(world).size() == 0) {
    //      stage.addActor(gameEndedWindow);
    //    }
    stage.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
    stage.draw();
}

From source file:com.dongbat.game.system.localSystem.LocalInputSystem.java

@Override
protected void processSystem() {
    UUID localPlayerId = LocalPlayerUtil.getLocalPlayer();
    e = UuidUtil.getEntityByUuid(world, localPlayerId);
    if (e == null || localPlayerId == null) {
        return;//from w  ww  .ja va2  s  .  com
    }
    UnitMovement move = EntityUtil.getComponent(world, e, UnitMovement.class);
    Vector2 destination = move.getDirectionVelocity();
    Vector2 position = PhysicsUtil.getPosition(world, e);
    if (touchDown) {
        if (ECSUtil.getFrame(world) - EntityUtil.getLastPlayerMovementInput(world, e) > 10) {
            Vector3 vector = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
            Vector3 unproject = getCamera().unproject(vector);
            long lastFrameIndex = ECSUtil.getFrame(world);
            Vector2 direction = new Vector2(unproject.x - position.x, unproject.y - position.y);
            CustomInput customInput = new CustomInput(direction);
            EntityUtil.getComponent(world, e, Player.class).getInputs().put(lastFrameIndex + 3, customInput);
        }
    }
    if (Gdx.input.isKeyJustPressed(Input.Keys.Q)) {
        AbilityUtil.use(world, e, "Flee", destination);
    }
    if (Gdx.input.isKeyJustPressed(Input.Keys.W)) {
        AbilityUtil.use(world, e, "HotBlow", destination);
    }
    if (Gdx.input.isKeyJustPressed(Input.Keys.E)) {
        AbilityUtil.use(world, e, "SplitAndJoin", destination);
    }
    if (Gdx.input.isKeyJustPressed(Input.Keys.R)) {
        AbilityUtil.use(world, e, "Vacuum", destination);
    }
}