Advertisement
MrsMcLead

Untitled

Jan 27th, 2014
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1.  public static void main(String[] args)
  2.   {
  3.     Draw.window(601,600);
  4.     Draw.setTitle("Bouncing Ball");
  5.     Draw.setFill(true);
  6.     int x = 0;
  7.     int y = 0;
  8.     int xDirection = 1;
  9.     int yDirection = 1;
  10.     while(true)
  11.     {
  12.       Draw.setColor(0,0,0);
  13.       Draw.oval(x,y,50,50);
  14.       Util.pause(.005);
  15.       Draw.setColor(255,255,255);
  16.       Draw.oval(x,y,50,50);
  17.      
  18.       x = x + xDirection;
  19.       if (x>550)
  20.       {
  21.         xDirection = Util.random(2,5);
  22.         xDirection = xDirection*-1;
  23.       }
  24.       if (x<0)
  25.          xDirection = Util.random(2,5);
  26.        
  27.      
  28.       y = y + yDirection;
  29.       if (y>550)
  30.       {
  31.         yDirection = Util.random(2,5);
  32.         yDirection = yDirection*-1;
  33.       }
  34.       if (y<0)
  35.         yDirection = Util.random(2,5);
  36.      
  37.     }
  38.    
  39.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement