|
|
@@ -11,8 +11,8 @@ public class Ball {
|
|
|
private int size, bounceheight;
|
|
|
private Ellipse2D.Double bal;
|
|
|
|
|
|
- double rx = 100, ry = 100; // position
|
|
|
- double vx = 1, vy = 1; // velocity
|
|
|
+ double rx, ry; // position
|
|
|
+ double vx = 1, vy = 1; // velocity
|
|
|
|
|
|
public Ball(int size, int bounceheight, Color color, int x, int y, int direction) {
|
|
|
this.color = color;
|
|
|
@@ -24,6 +24,16 @@ public class Ball {
|
|
|
bal = new Ellipse2D.Double(x, y, this.size, this.size);
|
|
|
}
|
|
|
|
|
|
+ public boolean hitLine(ShootingLine l){
|
|
|
+ return bal.intersects(l.getX(), l.getY()-l.getHeight(), l.getWidth(), l.getHeight());
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean hitPlayer(Player p){
|
|
|
+ return bal.intersects(p.getX(),p.getY(),p.getWidth(),p.getHeigth());
|
|
|
+ }
|
|
|
+
|
|
|
+ //** Drawing and Calculating **//
|
|
|
+
|
|
|
public void paint(Graphics2D g2d) {
|
|
|
g2d.setColor(color);
|
|
|
g2d.fill(bal);
|
|
|
@@ -46,7 +56,9 @@ public class Ball {
|
|
|
setX((int) rx);
|
|
|
setY((int) ry);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ //** Getters and Setters **//
|
|
|
+
|
|
|
public int getSize() {
|
|
|
return size/20;
|
|
|
}
|
|
|
@@ -82,28 +94,10 @@ public class Ball {
|
|
|
public void setY(int y) {
|
|
|
bal.setFrame(getX(), y, getWidth(), getHeight());
|
|
|
}
|
|
|
-
|
|
|
- public void setWidth(int w) {
|
|
|
- bal.setFrame(getX(), getY(), w, getHeight());
|
|
|
- }
|
|
|
-
|
|
|
- public void setHeight(int h) {
|
|
|
- bal.setFrame(getX(), getY(), getWidth(), h);
|
|
|
- }
|
|
|
|
|
|
public void setDirection(int d){
|
|
|
if(d == -1 || d == 1){
|
|
|
vx = d;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- public boolean hitLine(ShootingLine l){
|
|
|
- return bal.intersects(l.getX(), l.getY()-l.getHeight(), l.getWidth(), l.getHeight());
|
|
|
- }
|
|
|
-
|
|
|
- public boolean hitPlayer(Player p){
|
|
|
- return bal.intersects(p.getX(),p.getY(),p.getWidth(),p.getHeigth());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
}
|