Android Open Source - Marble-Run Ramp






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.entity;
//from  w  w  w.j a va2  s. co m
import nttu.edu.ball.Ball;
import nttu.edu.graphics.Art;
import nttu.edu.graphics.RenderView;
import android.graphics.Bitmap;

public class Ramp extends Funnel {
  
  public Ramp(float ratio) {
    super(ratio);
  }
  
  @Override
  public boolean checkCollision(Ball b) {
    if (b.position[0] > dstRect.left && b.position[0] < dstRect.right && b.position[1] > dstRect.top && b.position[1] < dstRect.bottom) {
      b.setRamp(this);
      return true;
    }
    else if (b.getRamp() != null && b.getRamp() == this) {
      b.setRamp(null);
      b.funnelDetector = false;
      b.funnelFlag1 = false;
      b.funnelFlag2 = false;
    }
    return false;
  }
  
  @Override
  public void place() {
    dstRect.set(position[0] - radius, position[1] - radius, position[0] + radius, position[1] + radius);
    float size = 10 * PIPE_SIZE * RenderView.AspectRatio;
    switch (direction) {
      case LEFT:
      default:
        //Point 1 (Top left)
        x1 = dstRect.left + size;
        y1 = dstRect.top;
        //Point 2 (Bottom left)
        x2 = dstRect.left + size;
        y2 = dstRect.bottom;
        break;
      case RIGHT:
        x1 = dstRect.right - size;
        y1 = dstRect.top;
        x2 = dstRect.right - size;
        y2 = dstRect.bottom;
        break;
      case UP:
        x1 = dstRect.left;
        y1 = dstRect.top + size;
        x2 = dstRect.right;
        y2 = dstRect.top + size;
        break;
      case DOWN:
        x1 = dstRect.left;
        y1 = dstRect.bottom - size;
        x2 = dstRect.right;
        y2 = dstRect.bottom - size;
        break;
    }
  }
  
  @Override
  public void setDirection(Direction d) {
    direction = d;
    switch (d) {
      case LEFT:
      default:
        matrix.reset();
        break;
      case RIGHT:
        matrix.reset();
        matrix.setScale(-1, 1);
        matrix.postRotate(0);
        matrix.postTranslate(-8, 0);
        break;
      case UP:
        matrix.reset();
        matrix.setScale(1, 1);
        matrix.postRotate(90);
        matrix.postTranslate(-8, 0);
        break;
      case DOWN:
        matrix.reset();
        matrix.setScale(1, 1);
        matrix.postRotate(-90);
        matrix.postTranslate(0, -8);
        break;
    }
    bitmap = Bitmap.createBitmap(Art.sprites, 48, 0, 8, 8, matrix, false);
    srcRect.set(0, 0, 8, 8);
  }
}




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