Android Open Source - BounceMe Ball






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.cse3345.f13.martin;
/*from w  ww.  ja v  a  2 s .  c om*/
import android.graphics.Canvas;
import android.graphics.Paint;

public class Ball {
  private int radius = 20;
  private int strokeRadius = 25;
  private final double gravity = .2;
  private int startX;
  private int startY;
  private double yacc = gravity;
  private double xacc = 0;
  private double xspeed = 0;
  private double yspeed = 0;
  private int xpos;
  private int ypos;
  private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  private Paint strokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  
  
  public Ball(int x , int y){
    xpos = startX = x;
    ypos = startY = y;
    mPaint.setColor(0xFF66BD4A);
    strokePaint.setColor(0xFFF2642F);
  }
  
  public void draw(Canvas can){
    can.drawCircle(xpos, ypos, strokeRadius, strokePaint);
    can.drawCircle(xpos, ypos, radius, mPaint);
    xacc = 0;
    yacc = gravity;
  }
  
  public boolean update(){
    //update the speeed based on the velocity
    xspeed += xacc;
    yspeed += yacc;
    
    //update the position based on the velocity
    xpos += xspeed;
    ypos += yspeed;
    
    /*//setting terminal velocity in the x and y planes
    if (xspeed > 20){ 
      xspeed = 20;
    }else if(xspeed < -20){
      xspeed = -10;
    }
    
    if (yspeed > 20){ 
      yspeed = 20;
    }else if(yspeed < -20){
      yspeed = -20;
    }*/
    
    
    return true;
  }
  
  public void wallBounce(){
    xspeed = -xspeed;
  }
  
  //how to ball moves when it is touched
  public void onTouch(int x){
    if(x == -1){
      xacc = -.05;
    }else if(x == -2){
      xacc = -.1;
    }else if(x == 1){
      xacc = .05;
    }else if(x == 2){
      xacc = .1;
    }else{
      xacc = 0;
    }
  }
  
  public void restart(){
    xpos = startX;
    ypos = startY;
    yspeed = 0;
    xspeed = 0;
    yacc = 0;
    xacc = 0;
  }
  
  public void setAcc(double xAdd, double yAdd){
    xacc += xAdd;
    yacc += yAdd;
  }
  
  public void setSize(int size){
    radius = size;
    strokeRadius = radius + (radius/4);
  }
  
  public int getX(){
    return xpos;
  }
  
  public int getY(){
    return ypos;
  }
  
  public int getRadius(){
    return radius;
  }
}




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