Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Rectangle;
- public class Ball extends Rectangle
- {
- int xspeed = 3;
- int yspeed = 3;
- int diameter = 16;
- Color colour = Color.RED;
- boolean onPaddle = true;
- /* This constructor could also set the ball starting at a random position and speed,
- * but I think we'll just start it on the paddle.
- */
- Ball() {
- // uncomment the following line if you want each ball to have a different random colour
- //colour = new Color(Color.HSBtoRGB((float)Math.random(), 1.0f, 1.0f));
- this.width = this.height = diameter;
- }
- /* This is called from the main BlockBreaker class in initialize()
- * as well as everytime the ball hits the bottom of the screen
- */
- void putOnPaddle(Rectangle p) {
- this.y = p.y - this.height;
- this.x = p.x + p.width/2;
- xspeed = yspeed = 3; //reset speeds
- onPaddle = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement