-
Notifications
You must be signed in to change notification settings - Fork 0
/
controls.js
47 lines (45 loc) · 1.25 KB
/
controls.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
class Controls {
constructor() {
this.forward = false;
this.left = false;
this.right = false;
this.reverse = false;
this.#addKeyboardListeners();
}
#addKeyboardListeners() {
document.onkeydown = (e) => {
switch(e.key) {
case 'ArrowUp':
this.forward = true;
break;
case 'ArrowLeft':
this.left = true;
break;
case 'ArrowRight':
this.right = true;
break;
case 'ArrowDown':
this.reverse = true;
break;
}
console.log(this);
}
document.onkeyup = (e) => {
switch(e.key) {
case 'ArrowUp':
this.forward = false;
break;
case 'ArrowLeft':
this.left = false;
break;
case 'ArrowRight':
this.right = false;
break;
case 'ArrowDown':
this.reverse = false;
break;
}
}
console.log(this);
}
}