Android Open Source - blocks-game Move Utils






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  w  w  .ja va2 s  . co m*/
public class MoveUtils {

    /**
     * Goes with maximum acceleration and velocity to reach dist = 0
     * Assuming vel and dist are on one line.
     *
     * @param v      current velocity - will be modified
     * @param d      target distance (and direction)
     * @param maxV   maximum velocity
     * @param maxAcc maximum acceleration
     */
    static float goAccFastestDec(float v, float d, float maxV, float maxAcc) {

        if (d < 0) {
            return -goAccFastestDec(-v, -d, maxV, maxAcc);
        }

        // can stop immediately after this step
        if (Math.abs(v - d) <= maxAcc) {
//            return d;
        }

        // maximum velocity for d that can be decelerated to stop properly without overshot
        final float limitV = (float) Math.sqrt(2 * d * maxAcc);

        if (v >= limitV) {
            // need to decelerate - almost there and will overshot
            v -= maxAcc;
            // do not decelerate more than necessary
//            v = Math.max(limitV, v - maxAcc);
//            v = Math.min(v, limitV);
        } else {
            // accelerate, but keep in mind limits
            v += maxAcc;
            v = Math.min(v, maxV);
            v = Math.min(v, limitV);
        }

//        v = Math.min(v, d);

        return v;

    }
}




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