-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInput.js
49 lines (48 loc) · 1.09 KB
/
Input.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
export class Input {
constructor() {
this.horizontal = 0;
this.vertical = 0;
}
update() {
this.horizontal = 0;
this.vertical = 0;
}
}
var input = new Input();
onkeydown = onkeyup = change;
function change(e) {
e = e;
if(e.type == 'keydown')
{
switch (e.keyCode) {
case 65:
input.horizontal = -1;
break;
case 87:
input.vertical = 1;
break;
case 83:
input.vertical = -1;
break;
case 68:
input.horizontal = 1;
break;
}
}else{
switch (e.keyCode) {
case 65:
input.horizontal = 0;
break;
case 87:
input.vertical = 0;
break;
case 83:
input.vertical = 0;
break;
case 68:
input.horizontal = 0;
break;
}
}
}
export {input};