-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.js
83 lines (72 loc) · 1.71 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
class Player {
constructor(unit) {
this.unit = unit;
this.set_keys();
}
set_keys() {
// https://developer.mozilla.org/fr/docs/Web/API/KeyboardEvent/keyCode
let left = keyboard(81),
up = keyboard(90),
right = keyboard(68),
down = keyboard(83);
left.press = () => {
if (right.isDown) {
unit.dx = 0;
} else {
unit.dx = -1;
}
};
left.release = () => {
if (!right.isDown) {
unit.dx = 0;
} else {
unit.dx = 1;
}
};
up.press = () => {
if (down.isDown) {
unit.dy = 0;
} else {
unit.dy = -1;
}
};
up.release = () => {
if (!down.isDown) {
unit.dy = 0;
} else {
unit.dy = 1;
}
};
right.press = () => {
if (left.isDown) {
unit.dx = 0;
} else {
unit.dx = 1;
}
};
right.release = () => {
if (!left.isDown) {
unit.dx = 0;
} else {
unit.dx = -1;
}
};
down.press = () => {
if (up.isDown) {
unit.dy = 0;
} else {
unit.dy = 1;
}
};
down.release = () => {
if (!up.isDown) {
unit.dy = 0;
} else {
unit.dy = -1;
}
};
app.stage.pointerdown = function (e) {
unit.shoot();
}
}
}