trying to create multiple bouncing balls from set paramaters java

时间:2016-04-04 16:36:10

标签: java

I am trying to create multiple balls that bounce around the number of balls that appear are of a set parameter the user types in everything is going fine i just cant get the balls to bounce

public class BallDemo 
{
private Canvas myCanvas;
private ArrayList<BoxBall> balls;
private Random x;
private Random y;

public BallDemo()
{
    myCanvas = new Canvas("Ball Demo", 600, 500);
    balls = new ArrayList<BoxBall>();

}

 public void boxounce(int balli)
{

    // draw the ground
    myCanvas.drawLine(50, ground, 550, ground);
    myCanvas.drawLine(50, ground4, 550, ground4);
    myCanvas.drawLine(ground2, 50, ground2, 400);
    myCanvas.drawLine(ground3, 50, ground3, 400);

   int i=0;

   boolean finished =  false;
    i = 0;

   while(!finished && i <= balli - 1) {


     myCanvas.wait(100);


     Random x = new Random();
     Random y = new Random();
     int x2= x.nextInt(300 - 50 + 1) + 50;
     int y2= y.nextInt(300 - 50 + 1) + 50;
     balls.add(new BoxBall(x2, y2, 16, Color.BLUE, ground, ground2, ground3, ground4, myCanvas,i));
     balls.get(i).draw(); 

balls.get(i).move();


  if(balls.get(i).getXPosition() >= 550 ) {
            finished = true;
        }

     i++;

}

}

0 个答案:

没有答案