Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void bounce(int numberOfBalls) {
- int ground = 400; // position of the ground line
- myCanvas.setVisible(true);
- ArrayList<BouncingBall> balls = new ArrayList<BouncingBall>(numberOfBalls);
- Dimension cSize = myCanvas.getSize();
- // draw the ground
- myCanvas.drawLine(50, ground, 550, ground);
- // crate and show the balls
- for(int i=0;i<numberOfBalls;i++) {
- balls.add(new BouncingBall(0, 0, 16, new Color((int)(Math.random()*Math.pow(256,3))), 24, myCanvas));
- }
- dBalls:while(true) {
- myCanvas.wait(50); // small delay
- for (int i=0;i<numberOfBalls;i++) {
- balls.get(i).move();
- if(balls.get(i).getXPosition() >= 550) {
- break dBalls;
- }
- }
- }
- for (int i=0;i<numberOfBalls;i++) {
- balls.get(i).erase();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement