Repository navigation
Expand file tree
/
Copy pathcontroller.js
More file actions
116 lines (101 loc) · 2.61 KB
/
Copy pathcontroller.js
File metadata and controls
116 lines (101 loc) · 2.61 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
function Control() {
this.space = false;
this.shift = false;
this.left = false;
this.right = false;
this.up = false;
this.down = false;
this.mouse_left = false;
this.mouse_right = false;
this.mouse_middle = false;
this.click_mouse_x = null;
this.click_mouse_y = null;
this.mouse_x = null;
this.mouse_y = null;
this.p = false;
this.attack = false;
initController();
}
function initController(){
if (!gamepad.init()) {
gamepadSupport = false;
}else{
// a new gamepad connected
gamepad.bind(Gamepad.Event.CONNECTED, function(device) {
});
gamepad.bind(Gamepad.Event.DISCONNECTED, function(device) {
// gamepad disconnected
});
gamepad.bind(Gamepad.Event.UNSUPPORTED, function(device) {
// an unsupported gamepad connected (add new mapping)
});
gamepad.bind(Gamepad.Event.TICK, function(gamepads) {
// gamepads were updated (around 60 times a second)
for (control in gamepads[0].state) {
//value = gamepads[i].state[control];
if(gamepads[0].state['A']){
ControllerUse = true;
Controller.space = true;
} else if(gamepadSupport && ControllerUse){
Controller.space = false;
}
if(gamepads[0].state['X']){
ControllerUse = true;
Controller.shift = true;
} else if(gamepadSupport && ControllerUse) {
Controller.shift = false;
}
if(gamepads[0].state['DPAD_LEFT']){
ControllerUse = true;
Controller.left = true;
} else if(gamepadSupport && ControllerUse) {
Controller.left = false;
}
if(gamepads[0].state['DPAD_RIGHT']){
ControllerUse = true;
Controller.right = true;
} else if(gamepadSupport && ControllerUse) {
Controller.right = false;
}
if(gamepads[0].state['DPAD_UP']){
ControllerUse = true;
Controller.up = true;
} else if(gamepadSupport && ControllerUse) {
Controller.up = false;
}
if(gamepads[0].state['DPAD_DOWN']){
ControllerUse = true;
Controller.down = true;
} else if(gamepadSupport && ControllerUse) {
Controller.down = false;
}
if(gamepads[0].state['B']){
ControllerUse = true;
Controller.attack = true;
} else if(gamepadSupport && ControllerUse) {
Controller.attack = false;
}
if(gamepads[0].state['RIGHT_STICK']){
ControllerUse = true;
Controller.e = true;
} else if(gamepadSupport && ControllerUse) {
Controller.e = false;
}
if(gamepads[0].state['BACK']){
ControllerUse = true;
Controller.r = true;
} else if(gamepadSupport && ControllerUse) {
Controller.r = false;
}
if(gamepads[0].state['START'] && !pauseToggle){
ControllerUse = true;
Controller.p = !Controller.p;
pauseToggle = true;
}
if(!gamepads[0].state['START']){
pauseToggle = false;
}
}
});
}
}