Android Open Source - BounceMe Level






From Project

Back to project page BounceMe.

License

The source code is released under:

MIT License

If you think the Android project BounceMe 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.example.bounceme;
/*w  w w  .j a v a  2s.co m*/
import android.graphics.Canvas;

public class Level {
  private Sling[] slings;
  private Ball ball;
  private Goal goal;
  public boolean running = true;
  public boolean win = false;
  private int width;
  private int height;
  
  public Level(int levelNum, int w, int h){
    width = w;
    height = h;

    switch(levelNum){
      case 1:
        slings = new Sling[1];
        slings[0] = new Sling(width/2, (height/3)*2, 0); 
        ball = new Ball(width/2, height/3);
        goal = new Goal(width/2 + 100, height/3 + 100);
        break;
      case 2:
        slings = new Sling[2];
        slings[0] = new Sling(width/3, (height/3)*2, 1); 
        slings[1] = new Sling((width/3)*2, (int) ((height/3)*1.5), 0); 
        ball = new Ball(width/3, height/6);
        goal = new Goal((width/3)*2, height/10 + 100);
        break;
      case 3:
        slings = new Sling[1];
        slings[0] = new Sling(width/5, (height/3)*2, 1);  
        ball = new Ball(width/5, height/3);
        goal = new Goal((width/5)*4, height/3);
        break;
      case 4:
        slings = new Sling[2];
        slings[0] = new Sling(400, 400, 0); 
        slings[1] = new Sling(800, 400, 0);
        ball = new Ball(100, 100);
        goal = new Goal(500, 500);
        break;
      case 5:
        slings = new Sling[2];
        slings[0] = new Sling(400, 400, 0); 
        slings[1] = new Sling(800, 400, 0);
        ball = new Ball(100, 100);
        goal = new Goal(500, 500);
        break;
      case 6:
        slings = new Sling[2];
        slings[0] = new Sling(400, 400, 0); 
        slings[1] = new Sling(800, 400, 0);
        ball = new Ball(100, 100);
        goal = new Goal(500, 500);
        break;
      case 7:
        slings = new Sling[2];
        slings[0] = new Sling(400, 400, 0); 
        slings[1] = new Sling(800, 400, 0);
        ball = new Ball(100, 100);
        goal = new Goal(500, 500);
        break;
      case 8:
        slings = new Sling[2];
        slings[0] = new Sling(400, 400, 0); 
        slings[1] = new Sling(800, 400, 0);
        ball = new Ball(100, 100);
        goal = new Goal(500, 500);
        break;
      case 9:
        slings = new Sling[2];
        slings[0] = new Sling(400, 400, 0); 
        slings[1] = new Sling(800, 400, 0);
        ball = new Ball(100, 100);
        goal = new Goal(500, 500);
        break;
      case 10:
        slings = new Sling[2];
        slings[0] = new Sling(400, 400, 0); 
        slings[1] = new Sling(800, 400, 0);
        ball = new Ball(100, 100);
        goal = new Goal(500, 500);
        break;
    }
  }
  
  public String animate(Canvas canvas, int w, int h){
    for(int i = 0; i < slings.length; i++){
      if(slings[i].update(ball)){
        slings[i].draw(canvas);
      }
    }
    
    if(goal.update(ball)){
      goal.draw(canvas);
    }else{
      return "win";
    }
    
    if(ball.update(w, h)){
      ball.draw(canvas);
    }else{
      return "reset";
    }
    
    return "continue";
  }
  
  public void moveBall(int pos){
    ball.onTouch(pos);
  }
  
  public void reset(){
    ball.restart();
  }
}




Java Source Code List

com.cse3345.f13.martin.Ball.java
com.cse3345.f13.martin.CreditActivity.java
com.cse3345.f13.martin.Goal.java
com.cse3345.f13.martin.LevelGen.java
com.cse3345.f13.martin.LevelPicker.java
com.cse3345.f13.martin.Level.java
com.cse3345.f13.martin.MenuActivity.java
com.cse3345.f13.martin.PlaySurfaceView.java
com.cse3345.f13.martin.SetActivity.java
com.cse3345.f13.martin.Sling.java
com.cse3345.f13.martin.TutActivity.java
com.cse3345.f13.martin.Wall.java
com.cse3345.f13.martin.WinActivity.java
com.example.bounceme.Ball.java
com.example.bounceme.CreditActivity.java
com.example.bounceme.Goal.java
com.example.bounceme.GridAdapter.java
com.example.bounceme.Level.java
com.example.bounceme.MenuActivity.java
com.example.bounceme.PlaySurfaceView.java
com.example.bounceme.SetActivity.java
com.example.bounceme.Sling.java
com.example.bounceme.WinActivity.java
com.example.bounceme.levelGen.java
com.example.bounceme.levelPicker.java