Advertisement
Guest User

bola

a guest
Aug 19th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. //creo una bola en el medio de la pantalla//
  2.  
  3. class bola {
  4.   float x = width/2;
  5.   float y = height/2;
  6.  
  7.   //para que la bola se mueva//
  8.   float velocidadx = random(1,5);
  9.   float velocidady = random(1,5);
  10.  
  11.   void movimiento() {
  12.     x = x + velocidadx;
  13.     y = y + velocidady;  
  14.   }
  15.  
  16.   //función que pone la bola en el centro de nuevo//
  17.   void reiniciar() {
  18.     x = width/2;
  19.     y = height/2;
  20.   }
  21.  
  22.   //indico que si llega a los bordes se invierta su velocidad//
  23.   void bordes() {
  24.     if (y < 0 || y > 465) {
  25.       velocidady *= -1;
  26.     }
  27.    
  28.     if (x > 620) {
  29.       reiniciar ();
  30.     }
  31.     if (x < 0) {
  32.       reiniciar ();
  33.     }
  34.    
  35.   }
  36.   //la relleno de blanco y le doy forma redonda//
  37.   void forma() {
  38.     fill(0);
  39.     ellipse(x,y,20,20);
  40.   }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement