Android Open Source - mgcube Movable Block






From Project

Back to project page mgcube.

License

The source code is released under:

qp is licensed under the Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported http://creativecommons.org/licenses/by-nc-nd/3.0/ Your are not allowed to publish this game under your name.

If you think the Android project mgcube 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 de.redlion.qb;
//from   www.  j  a  va 2 s.co m
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector3;

public class MovableBlock extends Renderable{

  public static int idCnt = 0;

  public int id= 0;
  
  public Vector3 direction = new Vector3(0,0,-1);
  
  public boolean isMoving = false;
  
  public MovableBlock(Vector3 position) {
    this.position = position;
    this.id = idCnt;
    idCnt++;
  }
  
  public void move(Vector3 dir) {
    direction = dir;
    setDirection();
    if(Resources.getInstance().musicOnOff) {
      Resources.getInstance().moveSFX.play();
    }
    this.isMoving = true;
  }
  
  public void setDirection() {
    if (Math.abs(this.direction.x) > Math.abs(this.direction.y) && Math.abs(this.direction.x) > Math.abs(this.direction.z)) {
      while (this.direction.x != -1 && this.direction.x != 1) {
        if (this.direction.x < 0)
          this.direction.x--;
        else
          this.direction.x++;
        if (this.direction.x < -1)
          this.direction.x = -1;
        if (this.direction.x > 1)
          this.direction.x = 1;
        this.direction.y = 0;
        this.direction.z = 0;
      }
    }
    if (Math.abs(this.direction.y) > Math.abs(this.direction.x) && Math.abs(this.direction.y) > Math.abs(this.direction.z)) {
      while (this.direction.y != -1 && this.direction.y != 1) {
        if (this.direction.y < 0)
          this.direction.y--;
        else
          this.direction.y++;
        if (this.direction.y < -1)
          this.direction.y = -1;
        if (this.direction.y > 1)
          this.direction.y = 1;
        this.direction.x = 0;
        this.direction.z = 0;
      }
    }
    if (Math.abs(this.direction.z) > Math.abs(this.direction.y) && Math.abs(this.direction.z) > Math.abs(this.direction.y)) {
      while (this.direction.z != -1 && this.direction.z != 1) {
        if (this.direction.z < 0)
          this.direction.z--;
        else
          this.direction.z++;
        if (this.direction.z < -1)
          this.direction.z = -1;
        if (this.direction.z > 1)
          this.direction.z = 1;
        this.direction.y = 0;
        this.direction.x = 0;
      }
    }
  }
  
  public void stop() {
    this.position.x = MathUtils.ceil(this.position.x-0.5f);
    this.position.y = MathUtils.ceil(this.position.y-0.5f);
    this.position.z = MathUtils.ceil(this.position.z-0.5f);
    if(this.position.x%2 !=0) this.position.x -=1;
    if(this.position.y%2 !=0) this.position.y -=1;
    if(this.position.z%2 !=0) this.position.z -=1;
    this.isMoving = false;
  }
  
}




Java Source Code List

de.redlion.qb.Block.java
de.redlion.qb.Constants.java
de.redlion.qb.DefaultScreen.java
de.redlion.qb.EditorBlock.java
de.redlion.qb.EditorScreen.java
de.redlion.qb.GameInstance.java
de.redlion.qb.GameScreen.java
de.redlion.qb.Helper.java
de.redlion.qb.HighScoreManager.java
de.redlion.qb.HighScoreTimeAttack.java
de.redlion.qb.HighScore.java
de.redlion.qb.IntroScreen.java
de.redlion.qb.LZW.java
de.redlion.qb.LevelButton.java
de.redlion.qb.LevelSelectScreen.java
de.redlion.qb.MainActivity.java
de.redlion.qb.MainMenuScreenReduced.java
de.redlion.qb.MainMenuScreen.java
de.redlion.qb.Main.java
de.redlion.qb.MovableBlock.java
de.redlion.qb.OptionsScreen.java
de.redlion.qb.Player.java
de.redlion.qb.Portal.java
de.redlion.qb.QBLogo.java
de.redlion.qb.Renderable.java
de.redlion.qb.Resources.java
de.redlion.qb.RobovmLauncher.java
de.redlion.qb.ScreenshotSaver.java
de.redlion.qb.Starter.java
de.redlion.qb.Switch.java
de.redlion.qb.SwitchableBlock.java
de.redlion.qb.Target.java
de.redlion.qb.TutorialScreen.java
de.redlion.qb.client.GwtLauncher.java
de.redlion.qb.shader.FastBloomShader.java
de.redlion.qb.shader.TVShader.java
de.redlion.qb.shader.TransShader.java