Android Open Source - Marble-Run New Cue






From Project

Back to project page Marble-Run.

License

The source code is released under:

Apache License

If you think the Android project Marble-Run 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 nttu.edu.alt;
/*  ww w .j a va  2 s .c  o  m*/
import nttu.edu.entity.Tee;
import nttu.edu.graphics.Art;
import nttu.edu.graphics.RenderView;
import nttu.edu.level.Stage;
import android.graphics.Canvas;

public class NewCue extends NewBall implements Obstacle {
  private boolean goalFlag;
  private boolean jumpFlag;
  private boolean soundFlag;
  private boolean deadFlag;
  private final float RADIUS;
  private float xBound;
  private float yBound;
  private float[] defaults;
  
  public NewCue(float w, float h, float ratio) {
    RADIUS = 8f * ratio;
    xBound = w;
    yBound = h;
    goalFlag = jumpFlag = soundFlag = deadFlag = false;
    this.bitmap = Art.sprites;
    this.srcRect.set(0, 0, 16, 16);
    this.dstRect.set(0, 0, 16, 16);
    
  }
  
  @Override
  public void tick(Stage s) {
  }
  
  /*
  @Override
  public void tick(Stage s) {
    if (this.bitmap != null) {
      if (s.newHole.check(this) || goalFlag) {
        if (!jumpFlag) {
          goalFlag = true;
          die();
          s.newHole.respond(this);
          
          position[0] -= speed[0];
          position[1] -= speed[1];
          speed[0] *= 0.1f;
          speed[1] *= 0.1f;
          
          keepInBoundary();
        }
        else {
          jump();
          if (position[2] <= 0f) {
            soundFlag = false;
            jumpFlag = false;
          }
        }
      }
      else {
        if (!deadFlag) {
          if (acceleration[2] < 0f)
            setJumpState();
          if (!jumpFlag || position[2] <= 0f) {
            if (!goalFlag) {
              for (Obstacle o : s.obstacles)
                if (o.check(this))
                  o.respond(this);
              keepInBoundary();
            }
          }
          else {
            if (soundFlag) {
              //PLAY
              soundFlag = false;
            }
            jump();
          }
        }
        else
          falling();
      }
      lockCamera();
    }
    else
      this.bitmap = Art.sprites;
  }*/
  
  @Override
  public void render(Canvas c, float centerX, float centerY) {
    if (bitmap != null) {
      float xOffset = position[0] - RenderView.cameraX;
      float yOffset = position[1] - RenderView.cameraY;
      move(centerX + xOffset, centerY + yOffset);
      c.drawBitmap(bitmap, srcRect, dstRect, null);
    }
  }
  
  @Override
  public void reset() {
    for (int i = 0; i < 3; i++)
      position[i] = defaults[i];
    jumpFlag = goalFlag = deadFlag = soundFlag = false;
    lockCamera();
  }
  
  public void setStartingPosition(Tee tee) {
    position[0] = tee.x;
    position[1] = tee.y;
    for (int i = 0; i < 3; i++)
      defaults[i] = position[i];
    keepInBoundary();
  }
  
  public boolean hasReachedGoal() {
    return goalFlag;
  }
  
  //===========  PRIVATE METHODS  =====================
  
  private void lockCamera() {
    RenderView.cameraX = position[0];
    RenderView.cameraY = position[1];
  }
  
  private void die() {
    if (!deadFlag)
      deadFlag = true;
    if (jumpFlag)
      jumpFlag = false;
  }
  
  private void jump() {
    speed[0] += acceleration[0];
    speed[1] += acceleration[1];
    position[0] -= speed[0];
    position[1] -= speed[1];
    speed[0] *= 0.1f;
    speed[1] *= 0.1f;
    keepInBoundary();
  }
  
  private void keepInBoundary() {
    if (position[0] > xBound + RADIUS)
      position[0] = xBound + RADIUS;
    if (position[1] > yBound + RADIUS)
      position[1] = yBound + RADIUS;
    if (position[0] < -RADIUS)
      position[0] = RADIUS;
    if (position[1] < -RADIUS)
      position[1] = -RADIUS;
  }
  
  private void move(float f, float g) {
    dstRect.set(f - RADIUS, g - RADIUS, f + RADIUS, g + RADIUS);
    if (jumpFlag || deadFlag) {
      float s = position[2] * RenderView.AspectRatio;
      dstRect.left -= s;
      dstRect.right += s;
      dstRect.top -= s;
      dstRect.bottom += s;
    }
  }
  
  private void setJumpState() {
    jumpFlag = true;
    soundFlag = true;
  }
  
  private void falling() {
    if (position[2] > -RADIUS) {
      float temp = 0.1f * position[2];
      position[2] -= 1.2f * temp;
    }
  }
  
  //===========  IMPLEMENTED METHODS  ===================
  
  public boolean check(Obstacle obstacle) {
    return false;
  }
  
  public void respond(Obstacle obstacle) {
    if (obstacle == this) {
      for (int i = 0; i < 2; i++) {
        //Not set to Verlet Integration, due to too much work.
        speed[i] += acceleration[i];
        position[i] -= speed[i];
        speed[i] *= 0.6f;
      }
    }
  }
  
}




Java Source Code List

nttu.edu.activities.LevelSelectionActivity.java
nttu.edu.activities.MenuActivity.java
nttu.edu.activities.NewLoadingActivity.java
nttu.edu.activities.PlayActivity.java
nttu.edu.activities.ScoreActivity.java
nttu.edu.activities.SettingsActivity.java
nttu.edu.alt.NewBall.java
nttu.edu.alt.NewCue.java
nttu.edu.alt.NewHole.java
nttu.edu.alt.Obstacle.java
nttu.edu.ball.Ball.java
nttu.edu.ball.Cue.java
nttu.edu.ball.Marble.java
nttu.edu.entity.Border.java
nttu.edu.entity.Bumper.java
nttu.edu.entity.Coin.java
nttu.edu.entity.Connector.java
nttu.edu.entity.CurvePipe.java
nttu.edu.entity.Entity.java
nttu.edu.entity.Funnel.java
nttu.edu.entity.Hole.java
nttu.edu.entity.Path.java
nttu.edu.entity.Pipe.java
nttu.edu.entity.Ramp.java
nttu.edu.entity.ShortFunnel.java
nttu.edu.entity.Tee.java
nttu.edu.entity.Terrain.java
nttu.edu.entity.Void.java
nttu.edu.graphics.Art.java
nttu.edu.graphics.RenderView.java
nttu.edu.handler.Accelero.java
nttu.edu.handler.ImageInfo.java
nttu.edu.handler.Info.java
nttu.edu.handler.Loading.java
nttu.edu.handler.ModPlayer.java
nttu.edu.handler.MusicHandler.java
nttu.edu.hud.BestScore.java
nttu.edu.hud.Compass.java
nttu.edu.hud.GoalCompass.java
nttu.edu.hud.HUDMenu.java
nttu.edu.hud.HUDScore.java
nttu.edu.hud.MarbleCompass.java
nttu.edu.hud.TimeBasedScore.java
nttu.edu.level.HUD.java
nttu.edu.level.Stage.java
nttu.edu.score.Format.java
nttu.edu.score.Score.java
nttu.edu.sound.Sound.java