-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBall.java
More file actions
54 lines (39 loc) · 725 Bytes
/
Ball.java
File metadata and controls
54 lines (39 loc) · 725 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package Thread;
import java.awt.geom.*;
/**
*
* @author Administrator
*
*/
public class Ball {
private static final int XSIZE=15;
private static final int YSIZE=15;
private double x=0;
private double y=0;
private double dx=1;
private double dy=1;
public void move(Rectangle2D bounds){
x+=dx;
y+=dy;
if(x<bounds.getMinX()){
x=bounds.getMinX();
dx=-dx;
}
if(x+XSIZE>=bounds.getMaxX()){
x=bounds.getMaxX()-XSIZE;
dx=-dx;
}
if(y<bounds.getMinY()){
y=bounds.getMinY();
dy=-dy;
}
if(y+YSIZE>=bounds.getMaxY()){
y=bounds.getMaxY()-YSIZE;
dy=-dy;
}
}
public Ellipse2D getShape()
{
return new Ellipse2D.Double(x,y,XSIZE,YSIZE);
}
}