Advertisement
boxglue

BrickBreaker game - ball

Aug 10th, 2020
1,313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Rectangle;
  3.  
  4. public class Ball extends Rectangle
  5. {
  6.    
  7.     int xspeed = 3;
  8.     int yspeed = 3;
  9.     int diameter = 16;
  10.     Color colour = Color.RED;
  11.     boolean onPaddle = true;
  12.    
  13.        
  14.     /* This constructor could also set the ball starting at a random position and speed,
  15.      * but I think we'll just start it on the paddle.
  16.      */
  17.     Ball() {       
  18.         // uncomment the following line if you want each ball to have a different random colour
  19.         //colour = new Color(Color.HSBtoRGB((float)Math.random(), 1.0f, 1.0f));
  20.         this.width = this.height = diameter;
  21.     }
  22.    
  23.     /* This is called from the main BlockBreaker class in initialize()
  24.      * as well as everytime the ball hits the bottom of the screen
  25.      */
  26.     void putOnPaddle(Rectangle p) {
  27.         this.y = p.y - this.height;
  28.         this.x = p.x + p.width/2;
  29.         xspeed = yspeed = 3;    //reset speeds
  30.         onPaddle = true;
  31.     }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement