-
Notifications
You must be signed in to change notification settings - Fork 2
/
player.js
63 lines (56 loc) · 1.4 KB
/
player.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
class Player {
constructor() {
this.reset();
}
reset() {
this.pos = createVector(width / 2 - droidImg.width * 2, height / 2 - 200);
this.jumpStep = 5;
this.jump = false;
this.vel = 0;
this.gravity = 0.3;
this.angle = 0;
}
show() {
push();
// var c;
// if (this.jump) {
// c = sin(this.angle) + sin(this.angle);
// } else {
// c = cos(this.angle - 29.9);
// }
translate(this.pos.x, this.pos.y);
// rotate(c);
image(droidImg, 0, 0);
pop();
}
update() {
this.vel += this.gravity;
this.pos.y += this.vel;
}
jumping() {
if (this.jump) {
this.vel = -this.jumpStep;
}
}
jatohKeTanah() {
if (this.pos.y + droidImg.height > height - base.height / 2) {
this.pos.y = height + droidImg.height;
play = false;
}
}
// food mewakili capcake, donut dan kawan-kawan
eat(food) {
if (this.pos.x < food.pos.x + food.r / 2 && this.pos.x + droidImg.width / 2 > food.pos.x - food.r / 2) {
if (this.pos.y < food.pos.y + food.r / 2 && this.pos.y + droidImg.height > food.pos.y - food.r / 2) {
return true;
}
}
}
hit(bug) {
if (this.pos.x < bug.pos.x + bug.r / 2 && this.pos.x + droidImg.width / 2 > bug.pos.x - bug.r / 2) {
if (this.pos.y < bug.pos.y + bug.r / 2 && this.pos.y + droidImg.height / 2 > bug.pos.y - bug.r / 2) {
return true;
}
}
}
}