Android Open Source - TinyVoxel Character Controller






From Project

Back to project page TinyVoxel.

License

The source code is released under:

GNU General Public License

If you think the Android project TinyVoxel 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 com.toet.TinyVoxel.GameControllers;
//  www. j  a v a2 s  .  c  om
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputAdapter;
import com.toet.TinyVoxel.Time;

/**
 * Created by Kajos on 27-1-14.
 */
public abstract class CharacterController extends InputAdapter {
    float prev[] = {0,0,0,0};
    boolean firstTouch[] = {true, true, true, true};

    int x = 0, y = 0;

    public int getX() {
        if (Gdx.input.isCursorCatched())
            return Gdx.graphics.getWidth() / 2;
        return x;
    }

    public int getY() {
        if (Gdx.input.isCursorCatched())
            return Gdx.graphics.getHeight() / 2;
        return y;
    }

    @Override
    public boolean touchDragged (int screenX, int screenY, int pointer) {
        x = screenX;
        y = screenY;
        prevDrag = 0f;
        return true;
    }

    @Override
    public boolean mouseMoved (int screenX, int screenY) {
        x = screenX;
        y = screenY;
        prevDrag = 0f;
        return false;
    }

    public void update() {
        setPoint(x, true, true);
        setPoint(y, false, true);
        setPoint(x, true, false);
        setPoint(y, false, false);

        loop();
        nowActionB = getBoolean(ACTION.Action);

        if (prevDrag < .5f)
            prevDrag += Time.getDelta();
    }

    public void setPoint(int value, boolean XorY, boolean alternative) {
        int id = !alternative ? 0 : 1;
        boolean button = alternative ? getBoolean(ACTION.Action) : getBoolean(ACTION.Drag);

        if (!XorY)
            id += 2;

        float result = 0f;

        float div;
        if (XorY) {
            div = Gdx.graphics.getWidth();
        } else {
            div = Gdx.graphics.getHeight();
        }

        float val = ((float)value / div - 0.5f);
        if (firstTouch[id] && button) {
            prev[id] = val;
            firstTouch[id] = false;
        } else if (button) {
            result = val - prev[id];
            prev[id] = val;
        } else {
            firstTouch[id] = true;
        }
        if (!alternative) {
            if (XorY) {
                setAction(ACTION.X, result);
            } else {
                setAction(ACTION.Y, result);
            }
        } else {
            if (XorY) {
                setAction(ACTION.AlternativeX, result);
            } else {
                setAction(ACTION.AlternativeY, result);
            }
        }
    }

    boolean prevActionB = false;
    boolean nowActionB = false;
    boolean prevDragB = false;
    boolean nowDragB = false;

    private void loop() {
        prevActionB = nowActionB;
        prevDragB = nowDragB;
        nowActionB = getBoolean(ACTION.Action);
        nowDragB = getBoolean(ACTION.Drag);
    }

    public boolean getReleaseActionPress() {
        return prevActionB == true && nowActionB == false;
    }

    public boolean getReleaseDragPress() {
        return prevDragB == true && nowDragB == false;
    }

    float prevDrag = 0f;
    public boolean getLongDragPress() {
        boolean now = getBoolean(ACTION.Drag);

        boolean result = prevDrag > .5f && now == true;
        if (result)
            prevDrag = 0f;

        return result;
    }

    public boolean getBoolean(ACTION action) {
        return actions[action.ordinal()] > 0f;
    }

    public float getFloat(ACTION action) {
        return actions[action.ordinal()];
    }

    public void setAction(ACTION action, float value) {
        actions[action.ordinal()] = value;
    }

    public void init() {

    }

    public enum ACTION {Forward, Left, Shift, X, Y, AlternativeX, AlternativeY, Action, Drag, Jump, DropMouse};
    protected float actions[] = {0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f};
}




Java Source Code List

com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration.java
com.badlogic.gdx.backends.gwt.GwtApplication.java
com.badlogic.gdx.backends.gwt.GwtGL20.java
com.badlogic.gdx.backends.gwt.GwtInput.java
com.badlogic.gdx.backends.gwt.GwtNet.java
com.badlogic.gdx.graphics.Pixmap.java
com.toet.TinyVoxel.Config.java
com.toet.TinyVoxel.Game.java
com.toet.TinyVoxel.IOSConfig.java
com.toet.TinyVoxel.IOSLauncher.java
com.toet.TinyVoxel.OuyaController.java
com.toet.TinyVoxel.Time.java
com.toet.TinyVoxel.Character.Character.java
com.toet.TinyVoxel.Debug.LogHandler.java
com.toet.TinyVoxel.GameControllers.CharacterController.java
com.toet.TinyVoxel.GameControllers.CustomTouchPad.java
com.toet.TinyVoxel.GameControllers.KeyBoardController.java
com.toet.TinyVoxel.GameControllers.TouchPadController.java
com.toet.TinyVoxel.Importer.BinvoxImporter.java
com.toet.TinyVoxel.Importer.DataInputStream.java
com.toet.TinyVoxel.Importer.MeshImporter.java
com.toet.TinyVoxel.Renderer.BlockBuilder.java
com.toet.TinyVoxel.Renderer.Floor.java
com.toet.TinyVoxel.Renderer.Manager.java
com.toet.TinyVoxel.Renderer.Bundles.ArrayBundle.java
com.toet.TinyVoxel.Renderer.Bundles.Bundle.java
com.toet.TinyVoxel.Renderer.Bundles.GridBundle.java
com.toet.TinyVoxel.Renderer.Bundles.GridInterface.java
com.toet.TinyVoxel.Renderer.Bundles.Grid.java
com.toet.TinyVoxel.Renderer.Bundles.GroundBundle.java
com.toet.TinyVoxel.Renderer.Bundles.SingleBundle.java
com.toet.TinyVoxel.Renderer.Bundles.TinyGrid.java
com.toet.TinyVoxel.Renderer.Tools.BrushUtils.java
com.toet.TinyVoxel.Renderer.Tools.GridUtils.java
com.toet.TinyVoxel.Renderer.Wrapped.WrappedBoolean.java
com.toet.TinyVoxel.Renderer.Wrapped.WrappedInteger.java
com.toet.TinyVoxel.Screens.GUI.java
com.toet.TinyVoxel.Screens.Menu.java
com.toet.TinyVoxel.Shaders.ShaderManager.java
com.toet.TinyVoxel.Shadow.ShadowManager.java
com.toet.TinyVoxel.Util.Box.java
com.toet.TinyVoxel.Util.FullscreenQuad.java
com.toet.TinyVoxel.Util.JobManager.java
com.toet.TinyVoxel.Util.NonBackedTexture.java
com.toet.TinyVoxel.Util.Position.java
com.toet.TinyVoxel.Util.RLEInputStream.java
com.toet.TinyVoxel.Util.RLEOutputStream.java
com.toet.TinyVoxel.Util.SimpleMath.java
com.toet.TinyVoxel.Util.StreamUtil.java
com.toet.TinyVoxel.android.AndroidConfig.java
com.toet.TinyVoxel.android.AndroidConfig.java
com.toet.TinyVoxel.android.AndroidLauncher.java
com.toet.TinyVoxel.android.AndroidLauncher.java
com.toet.TinyVoxel.client.GwtConfig.java
com.toet.TinyVoxel.client.HtmlLauncher.java
com.toet.TinyVoxel.desktop.DesktopConfig.java
com.toet.TinyVoxel.desktop.DesktopLauncher.java