forked from gn-math/html
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path129.html
More file actions
139 lines (127 loc) · 5.24 KB
/
129.html
File metadata and controls
139 lines (127 loc) · 5.24 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE html>
<html lang="en-us">
<head>
<base href="https://cdn.jsdelivr.net/gh/gn-math/assets@main/129/">
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flappy Bird Multiplayer</title>
<style>
html,
body {
background: #000;
width: 100%;
height: 100%;
overflow: visible;
padding: 0;
margin: 0;
}
div#gameContainer {
background: transparent !important;
position: absolute;
}
div#gameContainer canvas {
position: absolute;
}
div#gameContainer canvas[data-pixel-art="true"] {
position: absolute;
image-rendering: optimizeSpeed;
image-rendering: -webkit-crisp-edges;
image-rendering: -moz-crisp-edges;
image-rendering: -o-crisp-edges;
image-rendering: crisp-edges;
image-rendering: -webkit-optimize-contrast;
image-rendering: optimize-contrast;
image-rendering: pixelated;
-ms-interpolation-mode: nearest-neighbor;
}
</style>
</head>
<body>
<div id="gameContainer">
<canvas id="unity-canvas" data-pixel-art=""></canvas>
<script src="Build/V0.1.loader.js"></script>
<script>
function mergeFiles(fileParts) {
return new Promise((resolve, reject) => {
let buffers = [];
function fetchPart(index) {
if (index >= fileParts.length) {
let mergedBlob = new Blob(buffers);
let mergedFileUrl = URL.createObjectURL(mergedBlob);
resolve(mergedFileUrl);
return;
}
fetch(fileParts[index]).then(response => response.arrayBuffer()).then(data => {
buffers.push(data);
fetchPart(index + 1);
}).catch(reject);
}
fetchPart(0);
});
}
var parts = ["Build/V0.1.wasm.part1", "Build/V0.1.wasm.part2"];
Promise.all([
mergeFiles(parts)
]).then(([mergedUrl]) => {
var canvas = document.querySelector("#unity-canvas");
var config = {
dataUrl: "Build/V0.1.data",
frameworkUrl: "Build/V0.1.framework.js",
codeUrl: mergedUrl,
streamingAssetsUrl: "StreamingAssets",
companyName: "eli_hoffman",
productName: "Flappy Bird Multiplayer",
productVersion: "0.1",
};
var scaleToFit;
try {
scaleToFit = !!JSON.parse("");
} catch (e) {
scaleToFit = true;
}
function progressHandler(progress) {
var percent = progress * 100 + '%';
canvas.style.background = 'linear-gradient(to right, white, white ' + percent + ', transparent ' + percent + ', transparent) no-repeat center';
canvas.style.backgroundSize = '100% 1rem';
}
function onResize() {
var container = canvas.parentElement;
var w;
var h;
if (scaleToFit) {
w = window.innerWidth;
h = window.innerHeight;
var r = 800 / 600;
if (w * r > window.innerHeight) {
w = Math.min(w, Math.ceil(h / r));
}
h = Math.floor(w * r);
} else {
w = 600;
h = 800;
}
container.style.width = canvas.style.width = w + "px";
container.style.height = canvas.style.height = h + "px";
container.style.top = Math.floor((window.innerHeight - h) / 2) + "px";
container.style.left = Math.floor((window.innerWidth - w) / 2) + "px";
}
createUnityInstance(canvas, config, progressHandler).then(function (instance) {
canvas = instance.Module.canvas;
onResize();
});
window.addEventListener('resize', onResize);
onResize();
if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
// Mobile device style: fill the whole browser client area with the game canvas:
const meta = document.createElement('meta');
meta.name = 'viewport';
meta.content = 'width=device-width, height=device-height, initial-scale=1.0, user-scalable=no, shrink-to-fit=yes';
document.getElementsByTagName('head')[0].appendChild(meta);
}
}).catch(error => {
console.error(error);
});
</script>
</div>
</body>
</html>