-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.js
76 lines (70 loc) · 2.05 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
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
// Keyboard
var keysDown = {};
var fullScreen = false;
addEventListener("keydown", function (e) {
keysDown[e.keyCode] = true;
if(e.keyCode === 77) {
// Tecla M = muteBtn
toggleMute();
} else if(e.keyCode === 82) {
if(juego && juego.iniciado &&
!juego.pausado && !juego.apagado) {
restart();
}
} else if(e.keyCode === 70) {
// Tecla F = fullscreen
if(!fullScreen) {
requestFullscreen(document.body);
fullScreen = true;
} else {
exitFullscreen();
fullScreen = false;
}
} else if(e.keyCode === 27) {
// Esc
if(fullScreen) exitFullscreen();
} else if(e.keyCode === 76) {
// L
glob_debugMode = !glob_debugMode;
} else if(e.keyCode === 116 || e.keyCode === 122) {
// F5, F11
return true;
}
if(!juego || (juego.finalizado || juego.pausado || !juego.iniciado)) return true;
var evt = e ? e:window.event;
if (evt.preventDefault) evt.preventDefault();
evt.returnValue = false;
return false;
}, false);
addEventListener("keyup", function (e) {
delete keysDown[e.keyCode];
if(juego) {
juego.puedeRepetirSonidos(e.keyCode);
}
}, false);
var requestFullscreen = function (ele) {
if (ele.requestFullscreen) {
ele.requestFullscreen();
} else if (ele.webkitRequestFullscreen) {
ele.webkitRequestFullscreen();
} else if (ele.mozRequestFullScreen) {
ele.mozRequestFullScreen();
} else if (ele.msRequestFullscreen) {
ele.msRequestFullscreen();
} else {
console.log('Fullscreen API is not supported.');
}
};
var exitFullscreen = function () {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
} else {
console.log('Fullscreen API is not supported.');
}
};