|
|
@@ -2,67 +2,86 @@ package model.objects;
|
|
|
|
|
|
import java.awt.Color;
|
|
|
import java.awt.Graphics2D;
|
|
|
-import java.awt.Shape;
|
|
|
import java.awt.geom.Ellipse2D;
|
|
|
|
|
|
+import main.Window;
|
|
|
|
|
|
public class Ball {
|
|
|
private Color color;
|
|
|
private int size, bounceheight;
|
|
|
private Ellipse2D.Double bal;
|
|
|
-
|
|
|
- public Ball(int size, int bounceheight, Color color, int x, int y){
|
|
|
+
|
|
|
+ double rx = 100, ry = 100; // position
|
|
|
+ double vx = 1, vy = 1; // velocity
|
|
|
+
|
|
|
+ public Ball(int size, int bounceheight, Color color, int x, int y) {
|
|
|
this.color = color;
|
|
|
- this.size = size;
|
|
|
+ this.size = size*20;
|
|
|
this.bounceheight = bounceheight;
|
|
|
- bal = new Ellipse2D.Double(x,y,size*20,size*20);
|
|
|
+ bal = new Ellipse2D.Double(x, y, this.size, this.size);
|
|
|
}
|
|
|
-
|
|
|
- public void paint(Graphics2D g2d)
|
|
|
- {
|
|
|
+
|
|
|
+ public void paint(Graphics2D g2d) {
|
|
|
g2d.setColor(color);
|
|
|
g2d.fill(bal);
|
|
|
}
|
|
|
-
|
|
|
- public int getSize(){
|
|
|
+
|
|
|
+ public void update() {
|
|
|
+ if (rx >= (Window.WIDTH - size))
|
|
|
+ vx = -1;
|
|
|
+ else if (rx <= 0)
|
|
|
+ vx = 1;
|
|
|
+
|
|
|
+ if (ry <= (Window.HEIGHT - bounceheight))
|
|
|
+ vy= 3;
|
|
|
+ else if (ry >= (600-size))
|
|
|
+ vy = -3;
|
|
|
+
|
|
|
+ rx += vx;
|
|
|
+ ry += vy;
|
|
|
+
|
|
|
+ setX((int) rx);
|
|
|
+ setY((int) ry);
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getSize() {
|
|
|
return size;
|
|
|
}
|
|
|
-
|
|
|
- public int getBounceHeight(){
|
|
|
+
|
|
|
+ public int getBounceHeight() {
|
|
|
return bounceheight;
|
|
|
}
|
|
|
-
|
|
|
- public int getX(){
|
|
|
- return (int)bal.getX();
|
|
|
+
|
|
|
+ public int getX() {
|
|
|
+ return (int) bal.getX();
|
|
|
}
|
|
|
-
|
|
|
- public int getY(){
|
|
|
- return (int)bal.getY();
|
|
|
+
|
|
|
+ public int getY() {
|
|
|
+ return (int) bal.getY();
|
|
|
}
|
|
|
-
|
|
|
- public int getWidth(){
|
|
|
- return (int)bal.getWidth();
|
|
|
+
|
|
|
+ public int getWidth() {
|
|
|
+ return (int) bal.getWidth();
|
|
|
}
|
|
|
-
|
|
|
- public int getHeight(){
|
|
|
- return (int)bal.getHeight();
|
|
|
+
|
|
|
+ public int getHeight() {
|
|
|
+ return (int) bal.getHeight();
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- public void setX(int x){
|
|
|
- bal.setFrame(x, getY(), getWidth(),getHeight());
|
|
|
+
|
|
|
+ public void setX(int x) {
|
|
|
+ bal.setFrame(x, getY(), getWidth(), getHeight());
|
|
|
}
|
|
|
-
|
|
|
- public void setY(int y){
|
|
|
+
|
|
|
+ public void setY(int y) {
|
|
|
bal.setFrame(getX(), y, getWidth(), getHeight());
|
|
|
}
|
|
|
-
|
|
|
- public void setWidth(int w){
|
|
|
+
|
|
|
+ public void setWidth(int w) {
|
|
|
bal.setFrame(getX(), getY(), w, getHeight());
|
|
|
}
|
|
|
-
|
|
|
- public void setHeight(int h){
|
|
|
+
|
|
|
+ public void setHeight(int h) {
|
|
|
bal.setFrame(getX(), getY(), getWidth(), h);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|