-
Notifications
You must be signed in to change notification settings - Fork 0
/
jellyfish.js
41 lines (37 loc) · 1005 Bytes
/
jellyfish.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
function Jellyfish() {
this.y = height / 2;
this.x = 200;
this.r = 24 * height / 600;
this.gravity = speed > 7 ? 1 : 0.8;
this.lift = -18;
this.velocity = 0;
this.show = function () {
fill(255);
imageMode(CENTER);
if (userimg) jelly = userimg;
else
switch (pic) {
case 0:
jelly = s1;
break;
case 1:
jelly = s2;
break;
case 2:
jelly = s3;
break;
case 3:
jelly = torus;
}
image(jelly, this.x, this.y, 2 * this.r, 2 * this.r);
};
this.up = function () {
this.velocity += this.lift;
};
this.update = function () {
this.velocity += this.gravity;
this.velocity *= 0.9;
this.y += this.velocity;
this.y = constrain(this.y, this.r, height - this.r);
}
}