Guest User

Untitled

a guest
Jul 17th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. public void boxBounce(int balls){
  2. Rectangle box=new Rectangle(100,100,200,200);
  3. myCanvas.draw(box);
  4.  
  5. Random randomGen=new Random();
  6. ArrayList<BoxBall> listBalls=new ArrayList<BoxBall>();
  7. Color color;
  8. for(int i=0;i<balls;i++){
  9. int y=100+randomGen.nextInt(185);
  10. int x=100+randomGen.nextInt(185);
  11. int speed=1+randomGen.nextInt(6);
  12. if(speed<3){
  13. color=Color.black;
  14. }
  15. else if (speed<5){
  16. color=Color.red;
  17. }
  18. else{
  19. color=Color.blue;
  20. }
  21. BoxBall ball = new BoxBall(y,x,15,color,300,myCanvas,speed);
  22. listBalls.add(ball);
  23. ball.draw();
  24. }
  25. boolean finished = false;
  26. while(!finished){
  27. for(int i=0;i<listBalls.size();i++){
  28. listBalls.get(i).move();
  29. }
  30. myCanvas.wait(50);
  31. }
  32. }
Add Comment
Please, Sign In to add comment