Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void boxBounce(int balls){
- Rectangle box=new Rectangle(100,100,200,200);
- myCanvas.draw(box);
- Random randomGen=new Random();
- ArrayList<BoxBall> listBalls=new ArrayList<BoxBall>();
- Color color;
- for(int i=0;i<balls;i++){
- int y=100+randomGen.nextInt(185);
- int x=100+randomGen.nextInt(185);
- int speed=1+randomGen.nextInt(6);
- if(speed<3){
- color=Color.black;
- }
- else if (speed<5){
- color=Color.red;
- }
- else{
- color=Color.blue;
- }
- BoxBall ball = new BoxBall(y,x,15,color,300,myCanvas,speed);
- listBalls.add(ball);
- ball.draw();
- }
- boolean finished = false;
- while(!finished){
- for(int i=0;i<listBalls.size();i++){
- listBalls.get(i).move();
- }
- myCanvas.wait(50);
- }
- }
Add Comment
Please, Sign In to add comment