forked from AzazelN28/web-doom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoom.html
348 lines (308 loc) · 11.2 KB
/
doom.html
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Twitter Card -->
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@azazeln28">
<meta name="twitter:creator" content="@azazeln28">
<!-- Facebook Open Graph -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://azazeln28.neocities.org/games/doom">
<meta property="og:title" content="DOOM">
<meta property="og:description" content="DOOM® is a registered trademark of ZeniMax Media Inc. in the US and/or other countries. Id Software® is a registered trademark of ZeniMax Media Inc. in the US and/or other countries. WebDOOM is in no way affiliated with ZeniMax Media Inc. or id Software LLC and is not approved by ZeniMax Media Inc. or id Software.">
<meta property="og:image" content="https://azazeln28.neocities.org/games/doom/cover.png">
<link href="https://fonts.googleapis.com/css?family=Teko&display=swap" rel="stylesheet">
<title>DOOM</title>
<style>
html, body {
font-family: 'Teko', sans-serif;
font-size: 200%;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
background: black;
color: white;
}
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
canvas {
border: 0px none;
image-rendering: pixelated;
width: 160vh;
height: 100vh;
}
#container {
position: fixed;
display: flex;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
justify-content: center;
align-items: center;
}
#spinner-container {
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
}
#spinner {
height: 30px;
width: 30px;
margin: 0;
display: inline-block;
-webkit-animation: rotation .8s linear infinite;
-moz-animation: rotation .8s linear infinite;
-o-animation: rotation .8s linear infinite;
animation: rotation 0.8s linear infinite;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 5px solid transparent;
border-top: 5px solid hsl(0, 100%, 50%);
border-radius: 100%;
background-color:transparent;
}
#status {
display: inline-block;
vertical-align: top;
margin-top: 30px;
margin-left: 20px;
font-weight: bold;
color: hsl(0, 100%, 50%);
}
#progress {
height: 20px;
width: 300px;
}
progress::-moz-progress-bar,
progress::-webkit-progress-value {
background: hsl(0, 100%, 50%);
}
progress {
color: hsl(0, 100%, 50%);
}
@-webkit-keyframes rotation {
from {-webkit-transform: rotate(0deg);}
to {-webkit-transform: rotate(360deg);}
}
@-moz-keyframes rotation {
from {-moz-transform: rotate(0deg);}
to {-moz-transform: rotate(360deg);}
}
@-o-keyframes rotation {
from {-o-transform: rotate(0deg);}
to {-o-transform: rotate(360deg);}
}
@keyframes rotation {
from {transform: rotate(0deg);}
to {transform: rotate(360deg);}
}
</style>
</head>
<body>
<!-- Aquí antes estaba el logo de Emscripten -->
<div id="container">
<div id="spinner-container">
<div id="spinner"></div>
<div id="status">Downloading...</div>
<progress value="0" max="100" id="progress" hidden="1"></progress>
</div>
</div>
<!--
<span id="controls">
<span>
<input type="checkbox" id="resize">
Resize canvas
</span>
<span>
<input type="checkbox" id="pointerLock" checked>
Lock/hide mouse pointer
</span>
<span>
<input type="button" value="Fullscreen" onclick="Module.requestFullscreen(document.getElementById('pointerLock').checked, document.getElementById('resize').checked)">
</span>
</span>
-->
<canvas id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1></canvas>
<script type="text/javascript">
const statusElement = document.getElementById('status');
const progressElement = document.getElementById('progress');
const spinnerElement = document.getElementById('spinner');
document.addEventListener('G_SaveGame', (e) => {
console.log(e.detail)
})
var Module = {
preRun: [],
postRun: [],
onRuntimeInitialized: function() {
console.log('hola')
// Esto es una auténtica ñapaza
let frameID = undefined
const currentState = {
buttons: 0,
x: 0,
y: 0,
strafe: 0,
look: 0
}, previousState = {
buttons: 0,
x: 0,
y: 0,
strafe: 0,
look: 0
}
function frame() {
previousState.buttons = currentState.buttons
previousState.x = currentState.x
previousState.y = currentState.y
previousState.strafe = currentState.strafe
previousState.look = currentState.look
currentState.buttons = 0
currentState.x = 0
currentState.y = 0
currentState.strafe = 0
currentState.look = 0
const gamepads = navigator.getGamepads()
for (let index = 0; index < gamepads.length; index++) {
const gamepad = gamepads[index]
if (gamepad) {
const buttonLength = Math.min(20, gamepad.buttons.length)
for (let i = 0; i < buttonLength; i++) {
const button = gamepad.buttons[i]
if (button.pressed) {
currentState.buttons |= (1 << i)
}
}
if (gamepad.axes[0] < -0.1
|| gamepad.axes[0] > 0.1) {
currentState.strafe = gamepad.axes[0] < 0 ? -32767 : 32767
} else {
currentState.strafe = 0
}
if (gamepad.axes[1] < -0.1
|| gamepad.axes[1] > 0.1) {
currentState.y = gamepad.axes[1] < 0 ? -32767 : 32767
} else {
currentState.y = 0
}
if (gamepad.axes[2] < -0.1
|| gamepad.axes[2] > 0.1) {
currentState.x = gamepad.axes[2] < 0 ? -32767 : 32767
} else {
currentState.x = 0
}
}
}
Module._UpdateJoystick(currentState.buttons, currentState.x, currentState.y, currentState.strafe, currentState.look)
frameID = window.requestAnimationFrame(frame)
}
frameID = window.requestAnimationFrame(frame)
},
print: (function() {
const element = document.getElementById('output');
if (element) element.value = ''; // clear browser cache
return function(text) {
if (arguments.length > 1) {
text = Array.prototype.slice.call(arguments).join(' ');
}
// These replacements are necessary if you render to raw HTML
//text = text.replace(/&/g, "&");
//text = text.replace(/</g, "<");
//text = text.replace(/>/g, ">");
//text = text.replace('\n', '<br>', 'g');
console.log(text);
if (element) {
element.value += text + "\n";
element.scrollTop = element.scrollHeight; // focus on bottom
}
};
})(),
printErr: function(text) {
if (arguments.length > 1) {
text = Array.prototype.slice.call(arguments).join(' ');
}
console.error(text);
},
canvas: (function() {
const canvas = document.getElementById('canvas');
// As a default initial behavior, pop up an alert when webgl context is lost. To make your
// application robust, you may want to override this behavior before shipping!
// See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
canvas.addEventListener("webglcontextlost", function(e) {
alert('WebGL context lost. You will need to reload the page.');
e.preventDefault();
}, false);
return canvas;
})(),
setStatus: function(text) {
if (!Module.setStatus.last) {
Module.setStatus.last = { time: Date.now(), text: '' };
}
if (text === Module.setStatus.last.text) {
return;
}
var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
var now = Date.now();
if (m && now - Module.setStatus.last.time < 30) {
return; // if this is a progress update, skip it if too soon
}
Module.setStatus.last.time = now;
Module.setStatus.last.text = text;
if (m) {
text = m[1];
progressElement.value = parseInt(m[2])*100;
progressElement.max = parseInt(m[4])*100;
progressElement.hidden = false;
spinnerElement.hidden = false;
} else {
progressElement.value = null;
progressElement.max = null;
progressElement.hidden = true;
if (!text) {
spinnerElement.style.display = 'none';
}
}
statusElement.innerHTML = text;
},
totalDependencies: 0,
monitorRunDependencies: function(left) {
this.totalDependencies = Math.max(this.totalDependencies, left);
Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
}
};
Module.setStatus('Downloading...');
window.onblur = function() {
Module._SendPause(1)
Module.SDL2.audioContext.suspend()
}
window.onfocus = function() {
Module._SendPause(0)
Module.SDL2.audioContext.resume()
}
window.onclick = function(e) {
if (Module.SDL2.audioContext.state !== 'running') {
Module.SDL2.audioContext.resume()
}
}
window.onerror = function(event) {
// TODO: do not warn on ok events like simulating an infinite loop or exitStatus
Module.setStatus('Exception thrown, see JavaScript console');
spinnerElement.style.display = 'none';
Module.setStatus = function(text) {
if (text) {
Module.printErr('[post-exception status] ' + text);
}
};
};
</script>
<script async type="text/javascript" src="index.js"></script>
</body>
</html>