-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTimePilot.Controller.Keyboard2.js
80 lines (72 loc) · 2.52 KB
/
TimePilot.Controller.Keyboard2.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
/* global define */
define("TimePilot.Controller.Keyboard2", [
"engine/helpers"
], function (
helpers
) {
var Keyboard2 = function (controllerInterface) {
this._controllerInterface = controllerInterface;
this.connect();
};
Keyboard2.prototype = {
connect: function () {
var that = this;
helpers.bind("keydown", function (event) {
switch (event.keyCode) {
case 37: // Left-Key
case 65: // "A"
event.preventDefault();
that._controllerInterface.rotateAntiClockwise();
break;
case 39: // Right-Key
case 68: // "D"
event.preventDefault();
that._controllerInterface.rotateClockwise();
break;
case 32: // Space-Bar
event.preventDefault();
that._controllerInterface.startShooting();
break;
case 70: // "F"-Key
event.preventDefault();
that._controllerInterface.toggleFullScreen();
break;
case 27: // Escape-Key
event.preventDefault();
that._controllerInterface.openMenu();
that._controllerInterface.togglePause();
break;
case 80: // "P"-Key
event.preventDefault();
that._controllerInterface.togglePause();
break;
}
}, this._keyboardLock);
helpers.bind("keyup", function () {
switch (event.keyCode) {
case 27: // Escape-Key
case 70: // "F"-Key
case 80: // "P"-Key
event.preventDefault();
break;
case 37: // Left-Key
case 39: // Right-Key
case 65: // "A"
case 68: // "D"
event.preventDefault();
that._controllerInterface.stop();
break;
case 32: // Space-Bar
event.preventDefault();
that._controllerInterface.stopShooting();
break;
}
}, this._keyboardLock);
},
disconnect: function () {
helpers.unbind("keydown");
helpers.unbind("keyup");
}
};
return Keyboard2;
});