-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBlob.pde
More file actions
129 lines (112 loc) · 2.72 KB
/
Copy pathBlob.pde
File metadata and controls
129 lines (112 loc) · 2.72 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
class Blob {
FBlob bobby; // FBlob object
float size; // Size of the blob
int vCount = 20; // Vertex count
// Default Constructor
Blob()
{
size = 30;
bobby= new FBlob();
bobby.setAsCircle(startX, startY, 30, 20);
//bobby.setStroke(142, 68, 173);
// bobby.setStrokeWeight(3);
bobby.setFill(155, 89, 182);
bobby.setFriction(4);
bobby.setGrabbable(false);
bobby.setNoStroke();
world.add(bobby);
}
// Constructor
Blob(float startX, float startY)
{
size = 30;
bobby= new FBlob();
bobby.setAsCircle(startX, startY, 28, 20);
// bobby.setStroke(142, 68, 173);
bobby.setNoStroke();
bobby.setStrokeWeight(3);
bobby.setFill(155, 89, 182);
bobby.setFriction(4);
bobby.setGrabbable(false);
world.add(bobby);
}
/*
* Adds a force to the blob relative to the angle of roll passed in
*/
public void accelerate(float roll)
{
bobby.addForce(map(roll, 2, -2, -45, 45), -6);
}
public void decelerate(){
bobby.addForce(-60,5);
}
/*
* Adds a force of dx to the x direction and dy to the y direction
*/
public void addForce(float dx, float dy)
{
bobby.addForce(dx, dy);
}
/*
// Jump method for the blog (blob can only jump when touching
// and on top of the platform)
void jump(ArrayList<FLine> lines)
{
int numLines = lines.size();
// skip 10 verticles
for (int i = 0; i < numLines; i++)
{
// Check if the blob is touching the box and above it
if (isTouchingBody((FBody)lines.get(i))) //&& getY() < lines.get(i).getY())
{
bobby.addForce(3, -1000);
return;
}
}
}
*/
/*
* Returns true if one of the vertices of this blob is touching
* the FBody passed in (created my own method because the one
* in the fisica library doesn't work for blobs)
*/
boolean isTouchingBody(FBody body)
{
for (int i = 0; i < vCount; i++)
{
if (((FBody)bobby.getVertexBodies().get(i)).isTouchingBody(body))
{
return true;
}
}
return false;
}
/*
* Get and Set methods
*/
FBlob getBlob() { return bobby; }
/*
* getX() and getY() return the average x and y values of the vertices of the
* blob, respectively.
*/
public float getX() {
float x = 0;
vCount = bobby.getVertexBodies().size();
for (int i = 0; i < vCount; i++)
{
x += ((FBody)bobby.getVertexBodies().get(i)).getX();
}
x /= vCount;
return x;
}
public float getY() {
float y = 0;
vCount = bobby.getVertexBodies().size();
for (int i = 0; i < vCount; i++)
{
y += ((FBody)bobby.getVertexBodies().get(i)).getY();
}
y /= vCount;
return y;
}
}