-
Notifications
You must be signed in to change notification settings - Fork 1
/
borders.js
50 lines (49 loc) · 1.32 KB
/
borders.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
43
44
45
46
47
48
49
50
Vehicle.prototype.addBorder = function (border = 'boncyBorders', off = 0) {
if (border === 'boncyBorders') {
let offset = this.r + off;
if (this.pos.x > width - offset) {
this.pos.x = width - offset;
this.velocity.x *= -1;
}
if (this.pos.x < offset) {
this.pos.x = offset;
this.velocity.x *= -1;
}
if (this.pos.y > height - offset) {
this.pos.y = height - offset;
this.velocity.y *= -1;
}
if (this.pos.y < offset) {
this.pos.y = offset;
this.velocity.y *= -1;
}
};
if (border === 'fixedBorders') {
if (this.pos.x > width) {
this.pos.x = width;
}
if (this.pos.x < 0) {
this.pos.x = 0;
}
if (this.pos.y > height) {
this.pos.y = height;
}
if (this.pos.y < 0) {
this.pos.y = 0;
}
};
if (border === 'continousBorder') {
if (this.pos.x > width) {
this.pos.x = this.r;
}
if (this.pos.x < this.r) {
this.pos.x = width-this.r;
}
if (this.pos.y > height) {
this.pos.y = this.r;
}
if (this.pos.y < this.r) {
this.pos.y = height-this.r;
}
}
}