-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathBall.java
72 lines (55 loc) · 1.23 KB
/
Ball.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
import processing.core.*;
public class Ball extends Simulatable implements ShapeCircle, Drawable{
public float kAtrito = 17f;
public float getMass(){
return 0.300f;
}
public float getRadius(){
return 0.05f;
}
public float getKFactor(){
return 1.0f;
}
public boolean canCollide(Simulatable s){
if(s instanceof Goal && !(s instanceof GoalWall))
return false;
return true;
}
boolean isOn = true;
public boolean isOn(){
return isOn;
}
public void setOn(boolean on){
isOn = on;
}
// public boolean colliding(Simulatable b){
// return is;
// }
/*
Sets position of Ball and reset's speed, acceleration and force
*/
public void setPosition(PVector p){
force.set(0,0);
accel.set(0,0);
speed.set(0,0);
position.set(p.x,p.y);
}
public PVector getForce(float dt){
PVector forceSum = super.getForce(dt);
PVector atrito = getRealSpeed();
atrito.mult(dt);
atrito.mult(-1 * kAtrito);
forceSum.add(atrito);
return forceSum;
}
int ds = 0;
public void draw(PApplet canvas, float scale){
if(isOn())
canvas.fill(255,255,0);
else
canvas.fill(100,100,100);
canvas.stroke(0);
float size = getRadius() * scale * 2;
canvas.ellipse(position.x * scale, position.y * scale, size, size);
}
}