-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItem.java
95 lines (58 loc) · 1.35 KB
/
Item.java
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import java.awt.Graphics;
import java.util.Random;
public class Item {
private int x, y, dx, radius;
private Starthere sp;
private boolean createNew = false;
public boolean isCreateNew() {
return createNew;
}
public void setCreateNew(boolean createNew) {
this.createNew = createNew;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public Item(int x) {
// TODO Auto-generated constructor stub
this.x = x;
Random r = new Random();
y = r.nextInt(400) + radius;
radius = 10;
dx = -2;
}
public void update(Starthere sp, Ball b){
x+=dx;
this.sp = sp;
checkForCollision(b);
if (x < 0 - radius){
createNew = true;
}
}
private void checkForCollision(Ball b) {
// TODO Auto-generated method stub
int ballX = b.getX();
int ballY = b.getY();
int ballR= b.getRadius();
int a = x - ballX;
int bb = y - ballY;
int collide = radius + ballR;
//distance between object centers
double c = Math.sqrt((double) (a*a) + (double) (bb*bb));
if (c < collide){
performAction(b);
createNew = true;
}
}
protected void performAction(Ball b) {
// TODO Auto-generated method stub
}
public void paint(Graphics g){
//g.setColor(Color.GREEN);
g.fillOval(x-radius, y-radius, radius*2, radius*2);
//g.drawRect(x,y,width,height);
}
}