-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslingShot.js
More file actions
47 lines (41 loc) · 1.21 KB
/
Copy pathslingShot.js
File metadata and controls
47 lines (41 loc) · 1.21 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
class SlingShot {
constructor(bodyA, pointB) {
var options = {
bodyA: bodyA,
pointB: pointB,
length: 20,
stiffness: 0.1
}
this.sling = Constraint.create(options);
World.add(world, this.sling);
this.pointB = pointB;
}
fly() {
this.sling.bodyA = null;
}
attach(body) {
this.sling.bodyA = body;
}
display() {
if (this.sling.bodyA) {
if(this.sling.bodyA){
var pointA = this.sling.bodyA.position;
var pointB = this.pointB;
push();
strokeWeight(4);
stroke("brown");
if(pointA.x < 250 && pointA.x > 200) {
strokeWeight(7);
line(pointA.x, pointA.y, pointB.x - 10, pointB.y);
line(pointA.x, pointA.y, pointB.x + 30, pointB.y - 3);
}
else {
strokeWeight(3);
line(pointA.x, pointA.y, pointB.x - 10, pointB.y);
line(pointA.x, pointA.y, pointB.x + 30, pointB.y - 3);
}
pop();
}
}
}
}