-
Notifications
You must be signed in to change notification settings - Fork 3
/
SlingShot.js
42 lines (35 loc) · 1.05 KB
/
SlingShot.js
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
class SlingShot{
constructor(bodyA, pointB){
var options = {
bodyA: bodyA,
pointB: pointB,
stiffness: 0.04,
length: 10
}
this.img1 = loadImage("sling1.png");
this.img2 = loadImage("sling2.png");
this.img3 = loadImage("sling3.png");
this.sling = Constraint.create(options);
World.add(world, this.sling);
this.pointB = pointB;
}
display(){
image(this.img1,200,250);
image(this.img2,170,252);
if(this.sling.bodyA){
var pointA = this.sling.bodyA.position;
var pointB = this.pointB;
strokeWeight(4);
stroke(color(48,22,8));
line(pointA.x-20, pointA.y, pointB.x-5, pointB.y);
line(pointA.x-20, pointA.y, pointB.x+40, pointB.y-3);
image(this.img3,pointA.x-30,pointA.y-10,10,30);
}
}
fly(){
this.sling.bodyA = null;
}
reattach(bodyA){
this.sling.bodyA = bodyA;
}
}