|
|
@@ -9,18 +9,17 @@ import main.Window;
|
|
|
public class Ball {
|
|
|
private Color color;
|
|
|
private int size, bounceheight, direction;
|
|
|
- private boolean velocity;
|
|
|
private Ellipse2D.Double bal;
|
|
|
|
|
|
double rx, ry; // position
|
|
|
- double vx = 1, vy = 1; // velocity
|
|
|
+ double vx = 0, vy = 0; // velocity
|
|
|
|
|
|
- public Ball(int size, int bounceheight, Color color, int x, int y, int direction, boolean velocity) {
|
|
|
+ public Ball(int size, int bounceheight, Color color, int x, int y, int direction, double velocity) {
|
|
|
this.color = color;
|
|
|
this.size = size*20;
|
|
|
this.bounceheight = bounceheight;
|
|
|
this.direction = direction;
|
|
|
- this.velocity = velocity;
|
|
|
+ this.vy = velocity;
|
|
|
setDirection(direction);
|
|
|
rx = x;
|
|
|
ry = y;
|
|
|
@@ -36,7 +35,7 @@ public class Ball {
|
|
|
}
|
|
|
|
|
|
public Ball clone(){
|
|
|
- return new Ball(getSize(), getBounceHeight(), getColor(), getX(), getY(), direction, velocity);
|
|
|
+ return new Ball(getSize(), getBounceHeight(), getColor(), getX(), getY(), direction, vy);
|
|
|
}
|
|
|
|
|
|
//** Drawing and Calculating **//
|
|
|
@@ -44,6 +43,7 @@ public class Ball {
|
|
|
public void paint(Graphics2D g2d) {
|
|
|
g2d.setColor(color);
|
|
|
g2d.fill(bal);
|
|
|
+ g2d.drawLine(0, 600-bounceheight, 500, 600-bounceheight);
|
|
|
}
|
|
|
|
|
|
public void update() {
|
|
|
@@ -53,16 +53,23 @@ public class Ball {
|
|
|
vx = 1;
|
|
|
|
|
|
vy += 0.5;
|
|
|
+
|
|
|
+ if(ry+size < 600-bounceheight && vy < 0)
|
|
|
+ {
|
|
|
+ vy +=0.5;
|
|
|
+ }
|
|
|
+ else if(ry+size < 600-bounceheight && vy > 0)
|
|
|
+ {
|
|
|
+ vy -=0.2;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-// if (ry <= (Window.HEIGHT - bounceheight))
|
|
|
-// vy = 4;
|
|
|
-// else
|
|
|
if (ry >= (600-size))
|
|
|
vy *= -1;
|
|
|
|
|
|
rx += vx;
|
|
|
ry += vy;
|
|
|
-
|
|
|
setX((int) rx);
|
|
|
setY((int) ry);
|
|
|
}
|
|
|
@@ -111,5 +118,9 @@ public class Ball {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public double getYSpeed()
|
|
|
+ {
|
|
|
+ return vy;
|
|
|
+ }
|
|
|
|
|
|
}
|