-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathinputs.js
More file actions
82 lines (68 loc) · 1.82 KB
/
inputs.js
File metadata and controls
82 lines (68 loc) · 1.82 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
// Handle clicks in each state
h3.onmousedown = h3.ontouchstart = e => {
switch(state){
// Title
case 0:
black.style.opacity = 1;
if(window.h4)h4.remove();
music();
setTimeout(()=>{
state = 1;
init();
}, 1500);
break;
}
}
h4.onclick = () => {
fullscreen = 1-fullscreen;
if(fullscreen){
document.body.requestFullscreen();
}
else {
document.exitFullscreen();
}
onresize();
//h4.innerHTML = ["Go fullscreen","Quit fullscreen"][fullscreen];
}
// Handle key presses
k = []; // 88: X, 67: C, 69: E, 82: R
u = l = d = r = 0; // arrow keys / wasd / zqsd
skiptimer = 0;
onkeydown = onkeyup = e => {
k[e.which] = e.type[5]; // update k
if(e.which == 38 || e.which == 90 || e.which == 87){ u = e.type[5] } // u
if(e.which == 37 || e.which == 81 || e.which == 65){ l = e.type[5] } // l
if(e.which == 40 || e.which == 83){ d = e.type[5] } // d
if(e.which == 39 || e.which == 68){ r = e.type[5] } // r
if(e.which == 27) {
if(state && state < 11 && !skiptimer) {
win = 1;
skiptimer = 1;
setTimeout(()=>{skiptimer = 0;},state==8?10000:3000);
black.style.opacity = 1;
hud.style.opacity = 0;
train.style.transition = hud.style.transition = "1s";
viewport.style.transition = "none";
setTimeout(()=>{
scene.style.transition = "none";
viewport.style.perspective = default_perspective;
state++;
init();
}, 1500);
}
}
//console.log(e.which);
}
onresize = () => {
if(fullscreen){
if(window.innerWidth / window.innerHeight > 900 / 480){
all.style.transform = "scale(" + (window.innerHeight / 480) + ")"
}
else {
all.style.transform = "scale(" + (window.innerWidth / 900) + ")"
}
}
else {
all.style.transform = "";
}
}