-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ball.pde
76 lines (55 loc) · 1.59 KB
/
Ball.pde
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
public class Ball{
PVector position;
int colorR;
int colorG;
int colorB;
PVector velocity;
Table table;
int dimension;
boolean alive = true;
ArrayList<Bar> bosses = new ArrayList();
public Ball(int positionX, int positionY,
int colorR, int colorG, int colorB, int dimension, Table table){
position = new PVector(positionX, positionY);
this.colorR = colorR;
this.colorG = colorG;
this.colorB = colorB;
velocity = new PVector(0,0);
this.table = table;
this.dimension = dimension;
}
public void update(){
if(alive){
bounce();
position.x += velocity.x;
position.y += velocity.y;
fill(colorR, colorG, colorB);
ellipse(position.x, position.y, dimension, dimension);
}
}
public void bounce(){
if(position.x + (dimension/2) >= table.topLeftCorner.x + table.lengthX ||
position.x - (dimension/2) <= table.topLeftCorner.x){
velocity.x = -velocity.x;
}
if(position.y - (dimension/2) <= table.topLeftCorner.y){
velocity.y = -velocity.y;
}
if (position.y + (dimension/2) >=
table.topLeftCorner.y + table.lengthY){
alive = false;
System.out.println("sono morta");
}
for( Bar b : bosses){
if(position.y >= b.position.y
&& position.x >= b.position.x
&& position.x <= b.position.x+b.lengthX){
System.out.println("hit");
velocity.y = -velocity.y;
}
}
}
public void addBoss(Bar bar){
bosses.add(bar);
}
}