-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCircle.java
More file actions
50 lines (43 loc) · 1.04 KB
/
Circle.java
File metadata and controls
50 lines (43 loc) · 1.04 KB
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
import java.awt.*;
public class Circle {
public int x, y;
private int r;
public int vx, vy;
public boolean isFilled = false;
public Circle(int x, int y, int r, int vx, int vy) {
this.x = x;
this.y = y;
this.r = r;
this.vx = vx;
this.vy = vy;
}
public int getR() {
return r;
}
public void move(int minx, int miny, int maxx, int maxy) {
x += vx;
y += vy;
checkCollision(minx, miny, maxx, maxy);
}
private void checkCollision(int minx, int miny, int maxx, int maxy) {
if (x - r < minx) {
x = r;
vx = -vx;
}
if (x + r >= maxx) {
x = maxx - r;
vx = -vx;
}
if (y - r < miny) {
y = r;
vy = -vy;
}
if (y + r >= maxy) {
y = maxy - r;
vy = -vy;
}
}
public boolean contain(Point point) {
return (x - point.x) * (x - point.x) + (y - point.y) * (y - point.y) <= r * r;
}
}