Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
titaniumnetwork-dev
GitHub Repository: titaniumnetwork-dev/Incognito-old
Path: blob/main/static/src/gs/public/flappybird/__start__.js
1338 views
1
(function () {
2
var CANVAS_ID = 'application-canvas';
3
4
var canvas, devices, app;
5
6
var createCanvas = function () {
7
canvas = document.createElement('canvas');
8
canvas.setAttribute('id', CANVAS_ID);
9
canvas.setAttribute('tabindex', 0);
10
// canvas.style.visibility = 'hidden';
11
12
// Disable I-bar cursor on click+drag
13
canvas.onselectstart = function () { return false; };
14
15
document.body.appendChild(canvas);
16
17
return canvas;
18
};
19
20
var createInputDevices = function (canvas) {
21
var devices = {
22
elementInput: new pc.ElementInput(canvas, {
23
useMouse: INPUT_SETTINGS.useMouse,
24
useTouch: INPUT_SETTINGS.useTouch
25
}),
26
keyboard: INPUT_SETTINGS.useKeyboard ? new pc.Keyboard(window) : null,
27
mouse: INPUT_SETTINGS.useMouse ? new pc.Mouse(canvas) : null,
28
gamepads: INPUT_SETTINGS.useGamepads ? new pc.GamePads() : null,
29
touch: INPUT_SETTINGS.useTouch && pc.platform.touch ? new pc.TouchDevice(canvas) : null
30
};
31
32
return devices;
33
};
34
35
var configureCss = function (fillMode, width, height) {
36
// Configure resolution and resize event
37
if (canvas.classList) {
38
canvas.classList.add('fill-mode-' + fillMode);
39
}
40
41
// css media query for aspect ratio changes
42
var css = "@media screen and (min-aspect-ratio: " + width + "/" + height + ") {";
43
css += " #application-canvas.fill-mode-KEEP_ASPECT {";
44
css += " width: auto;";
45
css += " height: 100%;";
46
css += " margin: 0 auto;";
47
css += " }";
48
css += "}";
49
50
// append css to style
51
if (document.head.querySelector) {
52
document.head.querySelector('style').innerHTML += css;
53
}
54
};
55
56
var reflow = function () {
57
app.resizeCanvas(canvas.width, canvas.height);
58
canvas.style.width = '';
59
canvas.style.height = '';
60
61
var fillMode = app._fillMode;
62
63
if (fillMode == pc.FILLMODE_NONE || fillMode == pc.FILLMODE_KEEP_ASPECT) {
64
if ((fillMode == pc.FILLMODE_NONE && canvas.clientHeight < window.innerHeight) || (canvas.clientWidth / canvas.clientHeight >= window.innerWidth / window.innerHeight)) {
65
canvas.style.marginTop = Math.floor((window.innerHeight - canvas.clientHeight) / 2) + 'px';
66
} else {
67
canvas.style.marginTop = '';
68
}
69
}
70
};
71
72
var displayError = function (html) {
73
var div = document.createElement('div');
74
75
div.innerHTML = [
76
'<table style="background-color: #8CE; width: 100%; height: 100%;">',
77
' <tr>',
78
' <td align="center">',
79
' <div style="display: table-cell; vertical-align: middle;">',
80
' <div style="">' + html + '</div>',
81
' </div>',
82
' </td>',
83
' </tr>',
84
'</table>'
85
].join('\n');
86
87
document.body.appendChild(div);
88
};
89
90
canvas = createCanvas();
91
devices = createInputDevices(canvas);
92
93
try {
94
app = new pc.Application(canvas, {
95
elementInput: devices.elementInput,
96
keyboard: devices.keyboard,
97
mouse: devices.mouse,
98
gamepads: devices.gamepads,
99
touch: devices.touch,
100
graphicsDeviceOptions: window.CONTEXT_OPTIONS,
101
assetPrefix: window.ASSET_PREFIX || "",
102
scriptPrefix: window.SCRIPT_PREFIX || "",
103
scriptsOrder: window.SCRIPTS || []
104
});
105
} catch (e) {
106
if (e instanceof pc.UnsupportedBrowserError) {
107
displayError('This page requires a browser that supports WebGL.<br/>' +
108
'<a href="http://get.webgl.org">Click here to find out more.</a>');
109
} else if (e instanceof pc.ContextCreationError) {
110
displayError("It doesn't appear your computer can support WebGL.<br/>" +
111
'<a href="http://get.webgl.org/troubleshooting/">Click here for more information.</a>');
112
} else {
113
displayError('Could not initialize application. Error: ' + e);
114
}
115
116
return;
117
}
118
119
app.configure(CONFIG_FILENAME, function (err) {
120
if (err) {
121
console.error(err);
122
}
123
124
configureCss(app._fillMode, app._width, app._height);
125
reflow();
126
127
window.addEventListener('resize', reflow, false);
128
window.addEventListener('orientationchange', reflow, false);
129
130
app.preload(function (err) {
131
if (err) {
132
console.error(err);
133
}
134
135
app.loadScene(SCENE_PATH, function (err, scene) {
136
if (err) {
137
console.error(err);
138
}
139
140
app.start();
141
});
142
});
143
});
144
}());
145
146