Android Open Source - blocks-game Follower






From Project

Back to project page blocks-game.

License

The source code is released under:

Apache License

If you think the Android project blocks-game listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package cz.kotu.game.blocks;
// w  ww  .j  a  v a2 s  . c om
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;

class Follower extends Block {

    // helper fields
    final Vector2 target = new Vector2();
    final Vector2 target1 = new Vector2();
    final Vector2 dir = new Vector2();

    public void init() {
        target.set(MathUtils.round(pos.x), MathUtils.round(pos.y));
    }

    @Override
    public void update() {

        if (target.dst2(pos) < 0.0001) {
//                target.add(1, 0);
        }
        target1.set(target);
        final boolean snappedx = Math.abs(MathUtils.round(pos.x) - pos.x) < 0.01;
        final boolean snappedy = Math.abs(MathUtils.round(pos.y) - pos.y) < 0.01;
        if (snappedx && snappedy) {
            if (Math.abs(target1.x - pos.x) < Math.abs(target1.y - pos.y)) {
                target1.x = pos.x;
            } else {
                target1.y = pos.y;
            }
        } else {
            if (snappedx) {
                target1.x = pos.x;
            } else {
                target1.y = pos.y;
            }
        }
        dir.set(target1).sub(pos).scl(0.1f);

        pos.add(dir);

//            pos.set(target);


    }

    @Override
    void draw(SpriteBatch batch) {
        batch.draw(T.blockTextureRegion.get(6), target.x, target.y, 1, 1);
        super.draw(batch);
    }
}




Java Source Code List

com.badlogic.gradletest.DesktopLauncher.java
com.badlogicgames.gradletest.MainActivity.java
cz.kotu.game.blocks.BaseStage.java
cz.kotu.game.blocks.Block.java
cz.kotu.game.blocks.Draggable.java
cz.kotu.game.blocks.Follower.java
cz.kotu.game.blocks.GridStage.java
cz.kotu.game.blocks.GridUtils.java
cz.kotu.game.blocks.HelloApp.java
cz.kotu.game.blocks.MoveUtils.java
cz.kotu.game.blocks.Slider.java
cz.kotu.game.blocks.T.java
cz.kotu.game.blocks.hex.Axial.java
cz.kotu.game.blocks.hex.HexCoords3.java
cz.kotu.game.blocks.hex.HexGrid.java
cz.kotu.game.blocks.hex.HexGroup.java
cz.kotu.game.blocks.hex.HexPos.java
cz.kotu.game.blocks.hex.HexSet.java
cz.kotu.game.blocks.hex.HexStage.java
cz.kotu.game.blocks.hex.Hex.java
cz.kotu.grids.Dir.java
cz.kotu.grids.GenericGrid.java
cz.kotu.grids.LinPos.java
cz.kotu.grids.LinearGrid.java
cz.kotu.grids.Pos.java