Skip to content

Commit 1d72991

Browse files
authored
Merge pull request #444 from mcuz/master
bouncy bubbles example fixed #426
2 parents e86089b + 033a767 commit 1d72991

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

src/data/examples/en/13_Motion/04_Bouncy_Bubbles.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class Ball {
3838
constructor(xin, yin, din, idin, oin) {
3939
this.x = xin;
4040
this.y = yin;
41-
let vx = 0;
42-
let vy = 0;
41+
this.vx = 0;
42+
this.vy = 0;
4343
this.diameter = din;
4444
this.id = idin;
4545
this.others = oin;
@@ -61,31 +61,31 @@ class Ball {
6161
let targetY = this.y + sin(angle) * minDist;
6262
let ax = (targetX - this.others[i].x) * spring;
6363
let ay = (targetY - this.others[i].y) * spring;
64-
vx -= ax;
65-
vy -= ay;
64+
this.vx -= ax;
65+
this.vy -= ay;
6666
this.others[i].vx += ax;
6767
this.others[i].vy += ay;
6868
}
6969
}
7070
}
7171

7272
move() {
73-
vy += gravity;
74-
this.x += vx;
75-
this.y += vy;
73+
this.vy += gravity;
74+
this.x += this.vx;
75+
this.y += this.vy;
7676
if (this.x + this.diameter / 2 > width) {
7777
this.x = width - this.diameter / 2;
78-
vx *= friction;
78+
this.vx *= friction;
7979
} else if (this.x - this.diameter / 2 < 0) {
8080
this.x = this.diameter / 2;
81-
vx *= friction;
81+
this.vx *= friction;
8282
}
8383
if (this.y + this.diameter / 2 > height) {
8484
this.y = height - this.diameter / 2;
85-
vy *= friction;
85+
this.vy *= friction;
8686
} else if (this.y - this.diameter / 2 < 0) {
8787
this.y = this.diameter / 2;
88-
vy *= friction;
88+
this.vy *= friction;
8989
}
9090
}
9191

src/data/examples/es/13_Motion/04_Bouncy_Bubbles.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class Ball {
3838
constructor(xin, yin, din, idin, oin) {
3939
this.x = xin;
4040
this.y = yin;
41-
let vx = 0;
42-
let vy = 0;
41+
this.vx = 0;
42+
this.vy = 0;
4343
this.diameter = din;
4444
this.id = idin;
4545
this.others = oin;
@@ -61,31 +61,31 @@ class Ball {
6161
let targetY = this.y + sin(angle) * minDist;
6262
let ax = (targetX - this.others[i].x) * spring;
6363
let ay = (targetY - this.others[i].y) * spring;
64-
vx -= ax;
65-
vy -= ay;
64+
this.vx -= ax;
65+
this.vy -= ay;
6666
this.others[i].vx += ax;
6767
this.others[i].vy += ay;
6868
}
6969
}
7070
}
7171

7272
move() {
73-
vy += gravity;
74-
this.x += vx;
75-
this.y += vy;
73+
this.vy += gravity;
74+
this.x += this.vx;
75+
this.y += this.vy;
7676
if (this.x + this.diameter / 2 > width) {
7777
this.x = width - this.diameter / 2;
78-
vx *= friction;
78+
this.vx *= friction;
7979
} else if (this.x - this.diameter / 2 < 0) {
8080
this.x = this.diameter / 2;
81-
vx *= friction;
81+
this.vx *= friction;
8282
}
8383
if (this.y + this.diameter / 2 > height) {
8484
this.y = height - this.diameter / 2;
85-
vy *= friction;
85+
this.vy *= friction;
8686
} else if (this.y - this.diameter / 2 < 0) {
8787
this.y = this.diameter / 2;
88-
vy *= friction;
88+
this.vy *= friction;
8989
}
9090
}
9191

src/data/examples/zh-Hans/13_Motion/04_Bouncy_Bubbles.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class Ball {
3838
constructor(xin, yin, din, idin, oin) {
3939
this.x = xin;
4040
this.y = yin;
41-
let vx = 0;
42-
let vy = 0;
41+
this.vx = 0;
42+
this.vy = 0;
4343
this.diameter = din;
4444
this.id = idin;
4545
this.others = oin;
@@ -61,31 +61,31 @@ class Ball {
6161
let targetY = this.y + sin(angle) * minDist;
6262
let ax = (targetX - this.others[i].x) * spring;
6363
let ay = (targetY - this.others[i].y) * spring;
64-
vx -= ax;
65-
vy -= ay;
64+
this.vx -= ax;
65+
this.vy -= ay;
6666
this.others[i].vx += ax;
6767
this.others[i].vy += ay;
6868
}
6969
}
7070
}
7171

7272
move() {
73-
vy += gravity;
74-
this.x += vx;
75-
this.y += vy;
73+
this.vy += gravity;
74+
this.x += this.vx;
75+
this.y += this.vy;
7676
if (this.x + this.diameter / 2 > width) {
7777
this.x = width - this.diameter / 2;
78-
vx *= friction;
78+
this.vx *= friction;
7979
} else if (this.x - this.diameter / 2 < 0) {
8080
this.x = this.diameter / 2;
81-
vx *= friction;
81+
this.vx *= friction;
8282
}
8383
if (this.y + this.diameter / 2 > height) {
8484
this.y = height - this.diameter / 2;
85-
vy *= friction;
85+
this.vy *= friction;
8686
} else if (this.y - this.diameter / 2 < 0) {
8787
this.y = this.diameter / 2;
88-
vy *= friction;
88+
this.vy *= friction;
8989
}
9090
}
9191

0 commit comments

Comments
 (0)