-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathhuman.js
101 lines (97 loc) · 3.65 KB
/
human.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
let human = class {
constructor(gl, pos) {
this.scale = 1;
this.position = pos;
this.gl = gl;
this.score = 0;
this.base = pos[1];
this.angle = 0;
this.change = [0, 0, 0];
this.duck = -0.2;
this.head = new base(gl, [this.position[0], this.position[1] + 0.35, this.position[2]], 0.05 * this.scale, 0.05 * this.scale, 0.05 * this.scale, this.angle);
this.body = new base(gl, [this.position[0], this.position[1] + 0.2, this.position[2]], 0.1 * this.scale, 0.1 * this.scale, 0.1 * this.scale, this.angle);
this.left_leg = new base(gl, [this.position[0], this.position[1], this.position[2] - 0.05], 0.05 * this.scale, 0.105 * this.scale, 0.025 * this.scale, this.angle);
this.right_leg = new base(gl, [this.position[0], this.position[1], this.position[2] + 0.05], 0.05 * this.scale, 0.105 * this.scale, 0.025 * this.scale, this.angle);
console.log(this.head.angle);
this.jump = 0.65;
}
moveLeft() {
console.log(this.position[2]);
if (this.position[2] != -1.1) {
this.position[2] -= 1.1;
this.setPosition();
}
}
moveRight() {
console.log(this.position[2]);
if (this.position[2] != 1.1) {
console.log('move bc');
this.position[2] += 1.1;
this.setPosition();
}
}
moveUp() {
if (this.position[1] == this.base) {
this.position[1] += this.jump;
}
this.setPosition();
}
moveDown() {
if (this.position[1] > this.base) {
this.position[1] -= 0.025;
if (this.position[1] < this.base) {
this.position[1] = this.base;
}
}
this.setPosition();
}
fly() {
if (this.position[1] == this.base) {
this.position[1] += 2;
}
this.angle = 90;
this.change[1] = 0.2;
this.change[0] = -0.2;
this.setPosition();
}
reset() {
this.change = [0, 0, 0];
this.angle = 0;
if (this.position[1] < this.base) {
this.position[1] = this.base;
}
this.setPosition();
}
moveAhead(x) {
this.position[0] += x;
this.setPosition();
}
duckP() {
if (this.position[1] == this.base) {
this.change[1] = 0.2;
this.change[0] = -0.2;
this.position[1] -= 0.2;
}
this.setPosition();
}
newPosition(x, y, z) {
this.position = [x, y, z];
this.setPosition();
}
grayScale() {
this.head.uGray = (this.head.uGray == 0) ? 1 : 0;
this.body.uGray = (this.body.uGray == 0) ? 1 : 0;
this.left_leg.uGray = (this.left_leg.uGray == 0) ? 1 : 0;
this.right_leg.uGray = (this.right_leg.uGray == 0) ? 1 : 0;
}
setPosition() {
this.head = new base(this.gl, [this.position[0] - this.change[0], this.position[1] + 0.35 - this.change[1] / 2, this.position[2]],
0.05 * this.scale, 0.05 * this.scale, 0.05 * this.scale, 0);
this.body = new base(this.gl, [this.position[0], this.position[1] + 0.2, this.position[2]]
, 0.1 * this.scale, 0.1 * this.scale, 0.1 * this.scale, 0);
this.left_leg = new base(this.gl, [this.position[0] + this.change[0], this.position[1] + this.change[1],
this.position[2] - 0.05], 0.05 * this.scale, 0.105 * this.scale, 0.025 * this.scale, this.angle);
this.right_leg = new base(this.gl, [this.position[0] + this.change[0], this.position[1] + this.change[1],
this.position[2] + 0.05], 0.05 * this.scale, 0.105 * this.scale, 0.025 * this.scale, this.angle);
}
}