Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Graphics;
- public class Ball extends Block
- {
- private int xSpeed;
- private int ySpeed;
- public Ball()
- {
- super(200,200);
- xSpeed = 3;
- ySpeed = 1;
- }
- //add the other Ball constructors
- public Ball(int x, int y)
- {
- super(x, y);
- xSpeed = 3;
- ySpeed = 1;
- }
- public Ball(int x, int y, int wt, int ht)
- {
- super(x,y,wt,ht);
- xSpeed = 3;
- ySpeed = 1;
- }
- public Ball(int x, int y, int wt, int ht, Color c)
- {
- super(x, y, wt, ht, c);
- xSpeed = 3;
- ySpeed = 1;
- }
- public Ball(int x, int y, int wt, int ht, Color c, int xSpd, int ySpd)
- {
- super(x, y, wt, ht, c);
- xSpeed = xSpd;
- ySpeed = ySpd;
- }
- //add the set methods
- public void setXSpeed(int xSpd)
- {
- xSpeed = xSpd;
- }
- public void setYSpeed(int ySpd)
- {
- ySpeed = ySpd;
- }
- public void moveAndDraw(Graphics window)
- {
- //draw a white ball at old ball location
- Ball old = new Ball(getX(), getY());
- old.draw(window, Color.WHITE);
- setX(getX()+xSpeed);
- //setY
- setY(getY()+ySpeed);
- //draw the ball at its new location
- Ball nw = new Ball(getX(), getY());
- nw.draw(window, Color.BLUE);
- }
- public boolean equals(Object obj)
- {
- Ball lhs = (Ball) obj;
- if(this.getX()== lhs.getX() && this.getY() == lhs.getY() && this.getHeight() == lhs.getHeight() && this.getWidth() == lhs.getWidth() && this.getColor() == lhs.getColor() && this.getXSpeed() == lhs.getXSpeed() && this.getYSpeed() == lhs.getYSpeed())
- return true;
- return false;
- }
- //add the get methods
- public int getXSpeed()
- {
- return xSpeed;
- }
- public int getYSpeed()
- {
- return ySpeed;
- }
- //add a toString() method
- public String toString()
- {
- return getX() + " " + getY() + " " + getWidth() + " " + getHeight() + " " + getColor() + " " + getXSpeed() + " " + getYSpeed();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement