Up-in-the-Air – blob

You can use Git to clone the repository via the web URL. Download snapshot (zip)
Another easter egg added
[Up-in-the-Air] / main.js
1 "use strict";
2 // SPDX-License-Identifier: GPL-3.0-or-later
3 /**
4  * Up in the Air
5  * – a browser game created for FediJam 2024 –
6  * https://fietkau.media/up_in_the_air
7  *
8  * Copyright (c) Julian Fietkau
9  * See README.txt for details.
10  *
11  *******************************************************************************
12  *
13  * This program is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation, either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25  *
26  */
28 import * as THREE from '/three/three.module.js';
29 import { FontLoader } from '/three/addons/loaders/FontLoader.js';
30 import { TextGeometry } from '/three/addons/geometries/TextGeometry.js';
33 window['startUpInTheAirGame'] = (game) => {
35 if(!game.hasOwnProperty('deploymentOptions')) {
36   game['deploymentOptions'] = {};
37 }
38 const deploymentDefaults = {
39   'assetUrlPrefix': '',
40 };
41 for(let k in deploymentDefaults) {
42   if(!game['deploymentOptions'].hasOwnProperty(k)) {
43     game['deploymentOptions'][k] = deploymentDefaults[k];
44   }
45 }
47 game['fn'] = {};
49 game['fn'].playRandomSound = () => {
50   if(!game.view || !game.view.audioListener) {
51     return;
52   }
53   if(!game.view.lastSoundsCache) {
54     game.view.lastSoundsCache = [];
55   }
56   let index;
57   // We remember the last two notes played and make sure not to repeat one of those.
58   do {
59     index = 1 + Math.floor(Math.random() * 5);
60   } while(game.view.lastSoundsCache.includes(index));
61   game.view.lastSoundsCache.push(index);
62   if(game.view.lastSoundsCache.length > 2) {
63     game.view.lastSoundsCache.splice(0, 1);
64   }
65   let sound = new THREE.Audio(game.view.audioListener);
66   sound.setBuffer(game.assets['audio']['sound' + index + '-' + game.settings['audio']['theme']]);
67   sound.setVolume(game.settings['audio']['sounds']);
68   if(!game.view.muted && game.settings['audio']['sounds'] > 0) {
69     sound.play();
70   }
71 }
73 game['fn'].easeInOut = (val) => {
74   return -0.5 * Math.cos(val * Math.PI) + 0.5;
75 }
77 game['fn'].lerp = (start, end, progress) => {
78   return (1.0 - progress) * start + progress * end;
79 }
81 game['fn'].loadAllAssets = (renderProgressCallback) => {
82   game.assets = {};
83   game.assets.words = {
84     'thanks': ['thank you', 'thanks'],
85     'sorry': ['sorry', 'apologize'],
86     'emotion': ['blessed', 'fortunate', 'glad', 'happy', 'joyous', 'lucky', 'overjoyed', 'thankful'],
87     'verb_general': ['adore', 'appreciate', 'cherish', 'enjoy', 'like', 'love', 'treasure', 'value'],
88     'verb_person': ['admire', 'honor', 'love', 'respect', 'treasure', 'value'],
89     'trait': ['amazing', 'compassionate', 'delightful', 'genuine', 'generous', 'incredible', 'joyful', 'kind', 'passionate', 'patient', 'principled', 'refreshing', 'sweet'],
90   };
91   game.assets.wordList = [...new Set([].concat.apply([], Object.values(game.assets.words)))]; // no need to be sorted
92   game.assets.sentences = [
93     '{thanks} for always listening.',
94     '{thanks} for being there.',
95     '{thanks} for helping me when I needed it most.',
96     '{thanks} for being with me.',
97     '{thanks} for believing in me.',
98     '{thanks} for not giving up.',
99     '{thanks} for believing in me when I myself couldn’t.',
100     '{thanks} for standing by my side.',
101     '{sorry} for what I said.',
102     '{sorry} for not being there.',
103     '{sorry} for forgetting.',
104     '{sorry} for not telling you.',
105     '{sorry} for what I did.',
106     '{sorry} for back then.',
107     '{sorry} for not being honest.',
108     'Just being around you makes me feel {emotion}.',
109     'I have no words for how {emotion} you make me feel.',
110     'I always feel {emotion} in your presence.',
111     'I’m honestly {emotion}.',
112     'I feel {emotion} just for knowing you.',
113     'Every moment with you makes me feel {emotion}.',
114     'I {verb_person} you.',
115     'I {verb_person} you more than anything.',
116     'I deeply {verb_person} you.',
117     'I honestly {verb_person} you.',
118     'I really do {verb_person} you.',
119     'I {verb_general} every moment with you.',
120     'I {verb_general} the way you see the world.',
121     'I {verb_general} you the way you are.',
122     'I {verb_general} how {trait} you are.',
123     'I {verb_general} how {trait} you are.',
124     'I {verb_general} how {trait} you are.',
125     'I always {verb_general} how {trait} you are.',
126     'I deeply {verb_general} how {trait} you are.',
127     'Thinking about how {trait} you are always improves my mood.',
128     'You are the most {trait} person I know.',
129     'You are the most {trait} person I know.',
130     'Your {trait} personality always makes my day.',
131     'Your {trait} personality is my sunshine.',
132     'Your {trait} personality gives me strength.',
133     'I’m astonished how {trait} you are.',
134     'I hope I can learn to be as {trait} as you.',
135   ];
136   return new Promise((resolve, reject) => {
137     let todoList = {
138       'audio/wind.ogg': 72482,
139       'fonts/cookie.json': 37866,
140       'textures/cloud0a.png': 568,
141       'textures/cloud0b.png': 569,
142       'textures/cloud0c.png': 568,
143       'textures/cloud1a.png': 6932,
144       'textures/cloud1b.png': 6932,
145       'textures/cloud1c.png': 6933,
146       'textures/cloud2a.png': 4365,
147       'textures/cloud2b.png': 4364,
148       'textures/cloud2c.png': 4365,
149       'textures/cloud3a.png': 4000,
150       'textures/cloud3b.png': 3999,
151       'textures/cloud3c.png': 4001,
152       'textures/cloud4a.png': 3183,
153       'textures/cloud4b.png': 3182,
154       'textures/cloud4c.png': 3184,
155       'textures/cloud5a.png': 2066,
156       'textures/cloud5b.png': 2065,
157       'textures/cloud5c.png': 2066,
158       'textures/feather-black.png': 1026,
159       'textures/feather-blue.png': 1026,
160       'textures/feather-brown.png': 1027,
161       'textures/feather-green.png': 1028,
162       'textures/feather-orange.png': 1028,
163       'textures/feather-purple.png': 1028,
164       'textures/feather-red.png': 1024,
165       'textures/highcontrast-backdrop.png': 500,
166       'textures/pinwheel.png': 904,
167       'textures/house-day-1.png': 17819,
168       'textures/house-day-2.png': 598,
169       'textures/house-day-3.png': 646,
170       'textures/house-evening-1.png': 16939,
171       'textures/house-evening-2.png': 597,
172       'textures/house-evening-3.png': 646,
173     };
174     for(let unlockable of game.settings['unlocks']) {
175       if(unlockable == 'golden') {
176         todoList['textures/feather-golden.png'] = 1027;
177       } else if(unlockable == 'ghost') {
178         todoList['textures/feather-ghost.png'] = 1023;
179       } else {
180         let unlock = game['fn'].unlockWithKey('NIbp2kW5' + unlockable + 'e2ZDFl5Y');
181         if(unlock && unlock['type'] == 'feather') {
182           todoList['data:textures/feather-' + unlock['name']] = unlock['url'];
183         }
184       }
185     }
186     game.assets.audiothemes = [];
187     const audioThemes = {
188       'classical': [1636930, 34002, 34629, 25399, 16426, 26122],
189     }
190     for(let theme of Object.keys(audioThemes)) {
191       todoList['audio/music-' + theme + '.ogg'] = audioThemes[theme][0];
192       todoList['audio/sound1-' + theme + '.ogg'] = audioThemes[theme][1];
193       todoList['audio/sound2-' + theme + '.ogg'] = audioThemes[theme][2];
194       todoList['audio/sound3-' + theme + '.ogg'] = audioThemes[theme][3];
195       todoList['audio/sound4-' + theme + '.ogg'] = audioThemes[theme][4];
196       todoList['audio/sound5-' + theme + '.ogg'] = audioThemes[theme][5];
197       game.assets.audiothemes.push(theme);
198     }
199     let total = Object.keys(todoList).filter(k => !k.startsWith('data:')).map(k => todoList[k]).reduce((a, b) => a + b, 0);
200     let progress = {};
201     const loader = {
202       'audio': new THREE.AudioLoader(),
203       'fonts': new FontLoader(),
204       'textures': new THREE.TextureLoader(),
205     };
206     for(let todo in todoList) {
207       let isDataUri = todo.startsWith('data:');
208       if(isDataUri) {
209         todo = todo.slice(5);
210       } else {
211         progress[todo] = 0;
212       }
213       let segments = todo.split('/');
214       if(!(segments[0] in game.assets)) {
215         game.assets[segments[0]] = {};
216       }
217       if(!(segments[0] in loader)) {
218         reject('Unsupported resource: ' + todo);
219       }
220       let url = todo;
221       if(isDataUri) {
222         url = todoList['data:' + todo];
223       } else {
224         url = game['deploymentOptions']['assetUrlPrefix'] + url;
225       }
226       loader[segments[0]].load(url, (result) => {
227         if(segments[0] == 'textures') {
228           result.url = url;
229           result.colorSpace = THREE.SRGBColorSpace;
230           result.minFilter = THREE.NearestFilter;
231           result.magFilter = THREE.NearestFilter;
232           if(segments[1].split('.')[0].startsWith('feather-')) {
233             result.repeat = new THREE.Vector2(1, -1);
234             result.wrapT = THREE.RepeatWrapping;
235           } else if(segments[1].split('.')[0] == 'highcontrast-backdrop') {
236             result.repeat = new THREE.Vector2(25, 25);
237             result.wrapS = THREE.RepeatWrapping;
238             result.wrapT = THREE.RepeatWrapping;
239           }
240         }
241         game.assets[segments[0]][segments[1].split('.')[0]] = result;
242         if(todo in progress) {
243           progress[todo] = todoList[todo];
244           if(renderProgressCallback) {
245             renderProgressCallback(Object.keys(progress).map(k => progress[k]).reduce((a, b) => a + b, 0) / total);
246           }
247         }
248       }, (xhr) => {
249         if(todo in progress) {
250           progress[todo] = xhr.loaded;
251           if(renderProgressCallback) {
252             renderProgressCallback(Object.keys(progress).map(k => progress[k]).reduce((a, b) => a + b, 0) / total);
253           }
254         }
255       }, (err) => {
256         reject('Error while loading ' + todo + ': ' + err);
257       });
258     }
259     const loadingHeartbeat = () => {
260       let totalProgress = Object.keys(progress).map(k => progress[k]).reduce((a, b) => a + b, 0);
261       if(totalProgress == total) {
262         resolve(totalProgress);
263       } else {
264         setTimeout(loadingHeartbeat, 100);
265       }
266     };
267     setTimeout(loadingHeartbeat, 100);
268   });
271 game['fn'].applyForceToFeather = (vector) => {
272   game.objects.feather.speed.add(vector);
275 game['fn'].initializeGame = (canvas) => {
276   game.timeProgress = 0;
277   game.timeTotal = 258;
278   game.courseRadius = 50;
280   game.objects = {};
281   game.view = {};
282   game.view.muted = false;
283   game.view.canvas = canvas;
284   game.view.audioListener = new THREE.AudioListener();
285   game.ui.virtualInput = canvas.closest('.upInTheAirGame').querySelector('.virtual-input-widget');
287   const scene = new THREE.Scene();
288   game.view.camera = new THREE.PerspectiveCamera(75, canvas.width / canvas.height, 0.1, 1000);
289   game.view.camera.position.z = 5;
290   game.view.camera.add(game.view.audioListener);
291   game.view.ambientLight = new THREE.AmbientLight(0xffffff, 2);
292   scene.add(game.view.ambientLight);
293   game.view.directionalLight1 = new THREE.DirectionalLight(0xffffff, 1);
294   game.view.directionalLight1.position.set(1, 1, 1);
295   scene.add(game.view.directionalLight1);
296   game.view.directionalLight2 = new THREE.DirectionalLight(0xffffff, 1);
297   game.view.directionalLight2.position.set(-1, -1, 1);
298   scene.add(game.view.directionalLight2);
299   game.view.directionalLight3 = new THREE.DirectionalLight(0xffffff, 1);
300   game.view.directionalLight3.position.set(0, -1, 1);
301   scene.add(game.view.directionalLight3);
302   game.view.renderer = new THREE.WebGLRenderer({ canvas: canvas, antialias: false });
303   game.view.renderer.setSize(canvas.width, canvas.height);
304   game.view.renderer.setClearColor(0x808080, 1);
305   let resolution = Math.round(3200 / Math.pow(2, game.settings['graphics']));
306   game.view.canvas.width = resolution;
307   game.view.canvas.height = resolution;
308   game.view.camera.updateProjectionMatrix();
309   game.view.renderer.setSize(game.view.canvas.width, game.view.canvas.height);
310   game.view.clock = new THREE.Clock();
311   game.view.clock.previousTime = 0;
312   game.view.clock.getDeltaTime = () => {
313     const elapsedTime = game.view.clock.getElapsedTime();
314     const deltaTime = elapsedTime - game.view.clock.previousTime;
315     game.view.clock.previousTime = elapsedTime;
316     return deltaTime;
317   };
319   const pinwheelGeometry = new THREE.BoxGeometry(.9, .9, 0.01);
320   const pinwheelMaterial = new THREE.MeshPhongMaterial({
321     map: game.assets.textures.pinwheel,
322     transparent: true,
323     alphaTest: 0.5,
324     opacity: 0.0,
325   });
326   game.objects.pinwheel = new THREE.Mesh(pinwheelGeometry, [null, null, null, null, pinwheelMaterial, null]);
327   game.objects.pinwheel.position.setY(2);
328   game.objects.pinwheel.position.setZ(-1);
329   game.objects.pinwheel.opacity = 0;
330   scene.add(game.objects.pinwheel);
332   for(let time of ['day', 'evening']) {
333     game.objects[time + 'House'] = new THREE.Group();
334     for(let layer of [1, 2, 3]) {
335       let material = new THREE.MeshBasicMaterial({
336         map: game.assets['textures']['house-' + time + '-' + layer],
337         transparent: true,
338         alphaTest: 0.5,
339       });
340       let dimensions;
341       if(layer == 1) {
342         dimensions = [14, 14, 0, 0, -2];
343       } else if(layer == 2) {
344         dimensions = [6, 3.4455, -1.4, -3.6, -3];
345       } else if(layer == 3) {
346         dimensions = [10, 10, -4, -2, -6];
347       }
348       let mesh = new THREE.Mesh(new THREE.PlaneGeometry(dimensions[0], dimensions[1]), material);
349       mesh.position.set(dimensions[2], dimensions[3], dimensions[4]);
350       if(time == 'evening') {
351         mesh.position.setX(-mesh.position.x);
352       }
353       game.objects[time + 'House'].add(mesh);
354     }
355     game.objects[time + 'House'].position.set(-11.5, -game.courseRadius - 4, -7);
356     if(time == 'evening') {
357       game.objects[time + 'House'].position.x *= -1;
358     }
359   }
361   game.view.camera.position.set(-5, -game.courseRadius, game.view.camera.position.z);
362   game.view.scene = scene;
364   game['fn'].createMeshes();
365   game['fn'].createFeather();
366   game['fn'].reset();
368   function pinwheelPositionUpdate(game, viewportX, viewportY) {
369     const vFOV = THREE.MathUtils.degToRad(game.view.camera.fov);
370     const viewportHeight = 2 * Math.tan(vFOV / 2) * (game.view.camera.position.z - game.objects.pinwheel.position.z);
371     game.controls.positionX = viewportHeight * viewportX;
372     game.controls.positionY = - viewportHeight * viewportY;
373   }
375   function cursorMoveEvent(game, target, viewportLocalX, viewportLocalY, pressed) {
376     if(game.settings['controls'] == 'mouse' || game.settings['controls'] == 'touchpad') {
377       let sensorElem = game.view.canvas;
378       if(game.settings['controls'] == 'touchpad') {
379         sensorElem = game.ui.virtualInput;
380       }
381       let bbox = sensorElem.getBoundingClientRect();
382       // Intentional division by height instead of width in the following line, since
383       // three.js controls the vertical FOV. So if we ever change the aspect ratio from 1:1,
384       // y will still be in range (-0.5, 0.5), but the range for x will be smaller or larger.
385       let x = (viewportLocalX - bbox.x - (bbox.width / 2)) / bbox.height;
386       let y = (viewportLocalY - bbox.y - (bbox.height / 2)) / bbox.height;
387       if(game.settings['controls'] == 'touchpad') {
388         sensorElem.children[0].style.left = ((0.5 + x) * 100) + '%';
389         sensorElem.children[0].style.top = ((0.5 + y) * 100) + '%';
390       }
391       if(game.settings['controls'] == 'touchpad') {
392         x *= 1.05;
393         y *= 1.05;
394       }
395       // The pinwheel gets to go a little bit past the edge of the playing field.
396       const maxDist = 0.55;
397       if(game.settings['controls'] == 'mouse' || (pressed && Math.abs(x) <= maxDist && Math.abs(y) <= maxDist)) {
398         pinwheelPositionUpdate(game, x, y);
399       }
400     }
401     if(game.settings['controls'] == 'thumbstick') {
402       if(!game.ui.virtualInput.inProgress) {
403         return;
404       }
405       let bbox = game.ui.virtualInput.getBoundingClientRect();
406       let x, y;
407       if(pressed) {
408         x = (viewportLocalX - bbox.x - (bbox.width / 2)) / bbox.height;
409         y = (viewportLocalY - bbox.y - (bbox.height / 2)) / bbox.height;
410         let vLen = Math.sqrt(4 * x * x + 4 * y * y);
411         x = x / Math.max(vLen, 0.6);
412         y = y / Math.max(vLen, 0.6);
413       } else {
414         x = 0;
415         y = 0;
416       }
417       let speedScale = 7.0;
418       let deadZone = 0.2;
419       let speedX = x * 2;
420       if(Math.abs(speedX) < deadZone) {
421         speedX = 0.0;
422       }
423       let speedY = y * 2;
424       if(Math.abs(speedY) < deadZone) {
425         speedY = 0.0;
426       }
427       game.controls.speedX = speedScale * speedX;
428       game.controls.speedY = -1 * speedScale * speedY;
429       x *= 0.6;
430       y *= 0.6;
431       game.ui.virtualInput.children[0].style.left = ((0.5 + x) * 100) + '%';
432       game.ui.virtualInput.children[0].style.top = ((0.5 + y) * 100) + '%';
433     }
434   }
436   function keyboardEvent(game, key, motion) {
437     if(game.settings['controls'] != 'keyboard') {
438       return;
439     }
440     if(motion == 'down') {
441       if(game.controls.heldKeys.includes(key)) {
442         return;
443       }
444       game.controls.heldKeys.push(key);
445     } else {
446       if(game.controls.heldKeys.includes(key)) {
447         game.controls.heldKeys.splice(game.controls.heldKeys.indexOf(key), 1);
448       }
449     }
450     if(game.settings['keyboard']['tapmode']) {
451       if(motion != 'down') {
452         return;
453       }
454       if(game.settings['keyboard']['up'].includes(key)) {
455         game.controls.speedY = Math.max(0.0, game.controls.speedY + 2.0);
456       }
457       if(game.settings['keyboard']['down'].includes(key)) {
458         game.controls.speedY = Math.min(0.0, game.controls.speedY - 2.0);
459       }
460       if(game.settings['keyboard']['right'].includes(key)) {
461         game.controls.speedX = Math.max(0.0, game.controls.speedX + 2.0);
462       }
463       if(game.settings['keyboard']['left'].includes(key)) {
464         game.controls.speedX = Math.min(0.0, game.controls.speedX - 2.0);
465       }
466       return;
467     }
468     if(motion == 'down' && game.settings['keyboard']['up'].includes(key)) {
469       game.controls.accelY = 15.0;
470       game.controls.speedY = 0.0;
471     }
472     if(motion == 'down' && game.settings['keyboard']['down'].includes(key)) {
473       game.controls.accelY = -15.0;
474       game.controls.speedY = 0.0;
475     }
476     if(motion == 'down' && game.settings['keyboard']['right'].includes(key)) {
477       game.controls.accelX = 15.0;
478       game.controls.speedX = 0.0;
479     }
480     if(motion == 'down' && game.settings['keyboard']['left'].includes(key)) {
481       game.controls.accelX = -15.0;
482       game.controls.speedX = 0.0;
483     }
484     if(motion == 'up' && game.settings['keyboard']['up'].includes(key)) {
485       game.controls.accelY = Math.min(0.0, game.controls.accelY);
486       game.controls.speedY = Math.min(0.0, game.controls.speedY);
487     }
488     if(motion == 'up' && game.settings['keyboard']['down'].includes(key)) {
489       game.controls.accelY = Math.max(0.0, game.controls.accelY);
490       game.controls.speedY = Math.max(0.0, game.controls.speedY);
491     }
492     if(motion == 'up' && game.settings['keyboard']['right'].includes(key)) {
493       game.controls.accelX = Math.min(0.0, game.controls.accelX);
494       game.controls.speedX = Math.min(0.0, game.controls.speedX);
495     }
496     if(motion == 'up' && game.settings['keyboard']['left'].includes(key)) {
497       game.controls.accelX = Math.max(0.0, game.controls.accelX);
498       game.controls.speedX = Math.max(0.0, game.controls.speedX);
499     }
500   }
502   document.body.addEventListener('mousemove', e => cursorMoveEvent(game, e.target, e.clientX, e.clientY, (e.buttons % 2 == 1)));
503   document.body.addEventListener('mousedown', e => {
504     if(game.settings['controls'] == 'touchpad' || game.settings['controls'] == 'thumbstick') {
505       if(e.target.closest('.virtual-input-widget') == game.ui.virtualInput) {
506         game.ui.virtualInput.inProgress = true;
507         game.ui.virtualInput.children[0].style.display = 'block';
508         e.preventDefault();
509       } else {
510         game.ui.virtualInput.inProgress = false;
511         if(game.settings['controls'] == 'touchpad') {
512           game.ui.virtualInput.children[0].style.display = 'none';
513         }
514       }
515     }
516     cursorMoveEvent(game, e.target, e.clientX, e.clientY, (e.buttons % 2 == 1));
517   });
518   document.body.addEventListener('mouseup', e => {
519     cursorMoveEvent(game, e.target, e.clientX, e.clientY, (e.buttons % 2 == 1));
520     if(game.settings['controls'] == 'touchpad' || game.settings['controls'] == 'thumbstick') {
521       game.ui.virtualInput.inProgress = false;
522       if(game.settings['controls'] == 'touchpad') {
523         game.ui.virtualInput.children[0].style.display = 'none';
524       } else {
525         game.ui.virtualInput.children[0].style.transitionDuration = '50ms';
526         setTimeout(() => { game.ui.virtualInput.children[0].style.transitionDuration = '0ms'; }, 75);
527       }
528       cursorMoveEvent(game, e.target, 0, 0, false);
529     }
530   });
531   document.body.addEventListener('touchmove', e => cursorMoveEvent(game, e.target, e.touches[0].clientX, e.touches[0].clientY, true));
532   document.body.addEventListener('touchstart', e => {
533     if(game.settings['controls'] == 'touchpad' || game.settings['controls'] == 'thumbstick') {
534       if(e.target.closest('.virtual-input-widget') == game.ui.virtualInput) {
535         game.ui.virtualInput.inProgress = true;
536         game.ui.virtualInput.children[0].style.display = 'block';
537         e.preventDefault();
538       } else {
539         game.ui.virtualInput.inProgress = false;
540         if(game.settings['controls'] == 'touchpad') {
541           game.ui.virtualInput.children[0].style.display = 'none';
542         }
543       }
544     }
545     cursorMoveEvent(game, e.target, e.touches[0].clientX, e.touches[0].clientY, true);
546   });
547   document.body.addEventListener('touchend', e => {
548     if(e.target.closest('.ui-container') && game.settings['controls'] != 'mouse' && ['gameplay', 'openingcutscene', 'endingcutscene'].includes(game.ui.currentPage)) {
549       game['fn'].moveToPage('pause', true);
550       e.preventDefault();
551     }
552     if(game.settings['controls'] == 'touchpad' || game.settings['controls'] == 'thumbstick') {
553       game.ui.virtualInput.inProgress = false;
554       if(game.settings['controls'] == 'touchpad') {
555         game.ui.virtualInput.children[0].style.display = 'none';
556       } else {
557         game.ui.virtualInput.children[0].style.transitionDuration = '50ms';
558         setTimeout(() => { game.ui.virtualInput.children[0].style.transitionDuration = '0ms'; }, 75);
559       }
560       cursorMoveEvent(game, e.target, 0, 0, false);
561     }
562   });
563   document.body.addEventListener('keydown', e => keyboardEvent(game, e.key, 'down'));
564   document.body.addEventListener('keyup', e => keyboardEvent(game, e.key, 'up'));
566   // All vectors used by the game loop (no allocations inside)
567   game.var = {};
568   game.var.featherLocalPos = new THREE.Vector3();
569   game.var.featherBorderForce = new THREE.Vector3();
570   game.var.pinwheelDistance = new THREE.Vector3();
571   game.var.pinwheelRotationSpeed = 0;
572   game.var.notCollectedPos = new THREE.Vector3();
573   game.var.collectedPos = new THREE.Vector3();
574   game.var.endingEntryTrajectory = new THREE.Vector3();
575   game.var.endingExitTrajectory = new THREE.Vector3();
576   game.var.endingEntryRotation = new THREE.Vector3();
577   game.var.endingExitRotation = new THREE.Vector3();
578   game.view.renderer.setAnimationLoop(() => { game['fn'].animate(scene); });
581 game['fn'].prepareWordMesh = (word) => {
582   while(word.children.length > 0) {
583     word.remove(word.children[0]);
584   }
585   if(game.settings['graphics'] <= 2 && !game.settings['highcontrast']) {
586     for(let letter of word.text) {
587       let geometry = game.assets.fonts.geometry[letter];
588       let material = game.view.materials.letter;
589       if(geometry.customMaterial) {
590         material = geometry.customMaterial;
591       }
592       let mesh = new THREE.Mesh(geometry, material);
593       // We wrap each letter in a surrounding group in order to move the center point
594       // from the corner of the letter to its center. This makes rotations easier.
595       let container = new THREE.Group();
596       mesh.position.set(-game.assets.fonts.geometry[letter].dx, -game.assets.fonts.geometry[letter].dy, 0);
597       container.add(mesh);
598       word.add(container);
599     }
600   } else if(game.settings['graphics'] == 3 || game.settings['highcontrast']) {
601     let mesh = new THREE.Mesh(Object.values(game.assets.fonts.geometry)[0], game.view.materials.letter);
602     word.add(mesh);
603   }
606 game['fn'].reset = () => {
607   game.controls = {};
608   game.controls.positionX = 0;
609   game.controls.positionY = 0;
610   game.controls.speedX = 0;
611   game.controls.speedY = 0;
612   game.controls.accelX = 0;
613   game.controls.accelY = 0;
614   game.controls.heldKeys = [];
615   game.ui.reachedEnd = false;
616   if(game.settings['graphics'] <= 2 && !game.settings['highcontrast']) {
617     for(let i = 0; i < 6; i++) {
618      game.view.materials['cloud' + i].uniforms.lerp.value = 0.0;
619     }
620   }
621   game.view.scene.add(game.objects.dayHouse);
622   game.view.scene.remove(game.objects.eveningHouse);
623   game.objects.feather.position.set(-11.45, -game.courseRadius - 4.2, -9.9);
624   game.objects.feather.rotation.set(Math.PI, 0, Math.PI / 2.1);
625   game.objects.pinwheel.material[4].opacity = 0.0;
626   setTimeout(() => {
627     game.ui.root.querySelector('.ui-page.title').classList.remove('end');
628   }, 500);
630   if(game.objects.words) {
631     for(let word of game.objects.words) {
632       game.view.scene.remove(word);
633     }
634   }
635   game.objects.words = [];
636   game.objects.words.collectedCount = 0;
637   game.ui.hud.children[1].innerText = '0';
638   const interWordDistance = new THREE.Vector3();
639   let placementSuccess;
640   let wordList = [];
641   for(let i = 0; i < 100; i++) {
642     let angleInCourse;
643     let clusteringFunction = (val) => Math.max(0.15 + val / 2, 0.7 - 3 * Math.pow(0.75 - 2 * val, 2), 1 - 3 * Math.pow(1 - val, 2));
644     do {
645       angleInCourse = Math.random();
646     } while(clusteringFunction(angleInCourse) < Math.random());
647     angleInCourse = (0.08 + 0.87 * angleInCourse);
648     if(i == 0) {
649       angleInCourse = 0.05;
650     }
651     let randomCameraX = game.courseRadius * Math.sin(angleInCourse * 2 * Math.PI);
652     let randomCameraY = game.courseRadius * -Math.cos(angleInCourse * 2 * Math.PI);
653     let word = new THREE.Group();
654     if(wordList.length == 0) {
655       wordList.push(...game.assets.wordList);
656     }
657     let wordIndex = Math.floor(Math.random() * wordList.length);
658     word.text = wordList.splice(wordIndex, 1)[0];
659     game['fn'].prepareWordMesh(word);
660     word.randomAnimOffset = Math.random();
661     const vFOV = THREE.MathUtils.degToRad(game.view.camera.fov);
662     let attempts = 0;
663     do {
664       let randomPlacementRadius = Math.min(0.8, angleInCourse) * Math.tan(vFOV / 2) * Math.abs(word.position.z - game.view.camera.position.z);
665       if(i == 0) {
666         randomPlacementRadius = 0;
667       }
668       let randomPlacementAngle = Math.random() * 2 * Math.PI;
669       let randomPlacementX = Math.sin(randomPlacementAngle) * randomPlacementRadius;
670       let randomPlacementY = Math.cos(randomPlacementAngle) * randomPlacementRadius;
671       word.position.set(randomCameraX + randomPlacementX, randomCameraY + randomPlacementY, 0);
672       placementSuccess = true;
673       for(let j = 0; j < i; j++) {
674         if(interWordDistance.subVectors(word.position, game.objects.words[j].position).length() <= 1.2) {
675           placementSuccess = false;
676           break;
677         }
678       }
679       attempts += 1;
680       if(attempts >= 10) {
681         angleInCourse = 0.04 + 0.92 * Math.random();
682         attempts = 0;
683       }
684     } while(!placementSuccess);
685     game.view.scene.add(word);
686     game.objects.words.push(word);
687   }
690 game['fn'].animate = (scene) => {
691   if(!('startTime' in game)) {
692     game.startTime = game.view.clock.getElapsedTime();
693   }
694   if(game.ui.currentPage == 'pause') {
695     return;
696   }
697   let delta = Math.min(game.view.clock.getDeltaTime(), 1 / 12);
698   if(game.ui.currentPage == 'gameplay') {
699     delta = delta * (game.settings['difficulty']['speed'] / 100);
700   }
701   game.timeProgress = (game.timeProgress + delta);
703   if(game.settings['controls'] == 'gamepad') {
704     let speedScale = 7.0;
705     let deadZone = 0.2;
706     let speedX = [];
707     let speedY = [];
708     for(let gamepad of game.ui.gamepads) {
709       let sx = gamepad.axes[0];
710       if(Math.abs(sx) < deadZone) {
711         sx = 0.0;
712       }
713       speedX.push(sx);
714       let sy = gamepad.axes[1];
715       if(Math.abs(sy) < deadZone) {
716         sy = 0.0;
717       }
718       speedY.push(sy);
719     }
720     if(speedX.length > 0) {
721       speedX = speedX.reduce((s, a) => s + a, 0) / speedX.length;
722     } else {
723       speedX = 0;
724     }
725     if(speedY.length > 0) {
726       speedY = speedY.reduce((s, a) => s + a, 0) / speedY.length;
727     } else {
728       speedY = 0;
729     }
730     game.controls.speedX = speedScale * speedX;
731     game.controls.speedY = -1 * speedScale * speedY;
732   }
734   const maxPinwheelSpeed = 8.0;
735   const maxPinwheelDistance = 5.0;
736   game.controls.speedX += delta * game.controls.accelX;
737   game.controls.speedY += delta * game.controls.accelY;
738   game.controls.speedX = Math.min(maxPinwheelSpeed, Math.max(-maxPinwheelSpeed, game.controls.speedX));
739   game.controls.speedY = Math.min(maxPinwheelSpeed, Math.max(-maxPinwheelSpeed, game.controls.speedY));
740   game.controls.positionX += delta * game.controls.speedX;
741   game.controls.positionY += delta * game.controls.speedY;
742   if(game.controls.positionX > maxPinwheelDistance) {
743     game.controls.positionX = maxPinwheelDistance;
744     game.controls.speedX = Math.max(0.0, game.controls.speedX);
745     game.controls.accelX = Math.max(0.0, game.controls.accelX);
746   } else if(game.controls.positionX < -maxPinwheelDistance) {
747     game.controls.positionX = -maxPinwheelDistance;
748     game.controls.speedX = Math.min(0.0, game.controls.speedX);
749     game.controls.accelX = Math.min(0.0, game.controls.accelX);
750   }
751   if(game.controls.positionY > maxPinwheelDistance) {
752     game.controls.positionY = maxPinwheelDistance;
753     game.controls.speedY = Math.max(0.0, game.controls.speedY);
754     game.controls.accelY = Math.max(0.0, game.controls.accelY);
755   } else if(game.controls.positionY < -maxPinwheelDistance) {
756     game.controls.positionY = -maxPinwheelDistance;
757     game.controls.speedY = Math.min(0.0, game.controls.speedY);
758     game.controls.accelY = Math.min(0.0, game.controls.accelY);
759   }
761   if(game.ui.currentPage != 'gameplay') {
762     let cameraSwayFactor = 1;
763     if(game.settings['graphics'] == 3) {
764       cameraSwayFactor = 0;
765     }
766     let cameraX, cameraY;
767     if(['options', 'credits', 'outro', 'unlock'].includes(game.ui.currentPage)) {
768       cameraX = game.ui.reachedEnd ? 5 : -5;
769       cameraY = 0;
770     }
771     if(game.ui.currentPage == 'title') {
772       cameraX = -5;
773       cameraY = 0;
774       if(!game.ui.reachedEnd) {
775         game.objects.feather.position.set(cameraX - 8.45, -game.courseRadius - 6.4, -9.9);
776         game.objects.feather.rotation.set(Math.PI, 0, Math.PI / 2.1);
777       } else {
778         cameraX = 5;
779       }
780       if(!game.ui.reachedStart) {
781         if(game.timeProgress < 1) {
782           game.ui.root.querySelector('.ui-page.title h1').style.opacity = '0';
783           game.ui.root.querySelectorAll('.ui-page.title > button').forEach((btn) => {
784             btn.disabled = true;
785             btn.style.position = 'relative';
786             btn.style.left = '10em';
787             btn.style.opacity = '0';
788           });
789           game.ui.root.querySelector('.ui-page.title .footer').style.opacity = '0';
790           game.ui.root.querySelector('.ui-page.title .system-buttons').style.opacity = '0';
791           cameraX += Math.max(0.0, 1 - game['fn'].easeInOut(0.5 + game.timeProgress / 2));
792           cameraY += Math.max(0.0, 10 * Math.pow(0.5 - game.timeProgress / 2, 2));
793         } else if(game.timeProgress >= 1.0 && game.timeProgress <= 2.1) {
794           game.ui.root.querySelector('.ui-page.title h1').style.opacity = Math.min(1.0, game.timeProgress - 1.0).toFixed(2);
795         }
796         if(game.timeProgress >= 1.5 && game.timeProgress <= 3.0) {
797           game.ui.root.querySelectorAll('.ui-page.title > button').forEach((btn) => {
798             let timeOffset = Array.from(btn.parentNode.children).indexOf(btn) - 2;
799             btn.style.left = 10 * game['fn'].easeInOut(Math.max(0.0, Math.min(1.0, 0.3 * timeOffset + 2.5 - game.timeProgress))).toFixed(2) + 'em';
800             let opacity = game['fn'].easeInOut(Math.max(0.0, Math.min(1.0, -0.3 * timeOffset + game.timeProgress - 1.5)));
801             btn.style.opacity = opacity.toFixed(2);
802             if(opacity == 1.0) {
803               btn.disabled = false;
804             }
805           });
806         }
807         if(game.timeProgress >= 3.0 && game.timeProgress <= 4.0) {
808           game.ui.root.querySelector('.ui-page.title .footer').style.opacity = game['fn'].easeInOut(Math.max(0.0, Math.min(1.0, game.timeProgress - 3.0))).toFixed(2);
809           game.ui.root.querySelector('.ui-page.title .system-buttons').style.opacity = game['fn'].easeInOut(Math.max(0.0, Math.min(1.0, game.timeProgress - 3.0))).toFixed(2);
810         }
811         if(game.timeProgress > 4.0 && !game.ui.reachedStart) {
812           game.ui.root.querySelector('.ui-page.title h1').removeAttribute('style');
813           game.ui.root.querySelectorAll('.ui-page.title > button').forEach(btn => { btn.disabled = false; btn.removeAttribute('style'); });
814           game.ui.root.querySelector('.ui-page.title .footer').removeAttribute('style');
815           game.ui.root.querySelector('.ui-page.title .system-buttons').removeAttribute('style');
816           game.ui.reachedStart = true;
817         }
818       }
819     } else if(game.ui.currentPage == 'openingcutscene') {
820       cameraX = -5;
821       cameraY = 0;
822       if(game.ui.reachedEnd) {
823         game['fn'].reset();
824       }
825       if(game.timeProgress < 0.1 && !game.view.windSound.isPlaying) {
826         game.view.windSound.stop();
827         game.objects.feather.position.set(cameraX - 8.45, -game.courseRadius - 6.4, -9.9);
828         game.objects.feather.rotation.set(Math.PI, 0, Math.PI / 2.1);
829       }
830       if(game.timeProgress > 1.0 && game.timeProgress <= 1.1 && !game.ui.root.querySelector('.gameplay p')) {
831         const lines = ['Why are the simplest words…', '…often the most difficult to write?'];
832         for(let line of lines) {
833           let elem = document.createElement('p');
834           elem.innerText = line;
835           elem.style.left = (1.5 + 2 * lines.indexOf(line)) + 'em';
836           elem.style.top = (1 + 1.2 * lines.indexOf(line)) + 'em';
837           elem.style.opacity = '0';
838           document.querySelector('.ui-page.gameplay').appendChild(elem);
839         }
840         if(!game.view.windSound.isPlaying) {
841           game.view.windSound.setVolume(game.settings['audio']['sounds']);
842           game.view.windSound.offset = 0;
843           if(!game.view.muted) {
844             game.view.windSound.play();
845           }
846         }
847       }
848       if(game.timeProgress > 1.0 && game.timeProgress <= 5.0) {
849         game.ui.root.querySelectorAll('.ui-page.gameplay p').forEach((elem) => {
850           let opacity = Math.max(0.0, Math.min(1.0, game.timeProgress - (elem.nextSibling ? 1.0 : 3.5)));
851           elem.style.transform = 'translateX(' + (Math.pow(1.0 - opacity, 2) * 10).toFixed(2) + 'em)';
852           elem.style.opacity = opacity.toFixed(2);
853         });
854       }
855       if(game.timeProgress >= 1.0 && game.timeProgress <= 3.0) {
856         let windStrength = 0.5 * (1 + Math.cos((game.timeProgress - 2.0) * Math.PI));
857         game.objects.feather.position.x = cameraX - 8.45 + 0.15 * windStrength;
858         game.objects.feather.rotation.z = Math.PI / 2.1 - 0.2 * windStrength;
859       }
860       if(game.timeProgress >= 3.0) {
861         let windStrength = Math.max(0.5 * (1 + Math.cos((game.timeProgress - 4.0) * Math.PI)), Math.min(2 * (game.timeProgress - 4.2), 1.2));
862         game.objects.feather.position.x = cameraX - 8.45 + 0.15 * windStrength + 13.45 * Math.min(1.0, Math.max(0.0, 1 - Math.pow(Math.max(0.0, 6.0 - game.timeProgress), 2)));
863         game.objects.feather.position.y = -game.courseRadius - 6.4 + 6.4 * game['fn'].easeInOut(Math.min(1,Math.max(0, game.timeProgress - 5.0) / 2));
864         game.objects.feather.position.y += (Math.cos((Math.max(5.0, Math.min(8.0, game.timeProgress)) - 5.0) * 2 * Math.PI / 3) - 1) * 2 * Math.sin(game.timeProgress * 2);
865         game.objects.feather.position.z = -9.9 + 9.9 * Math.min(1.0, Math.max(0.0, 1 - Math.pow(Math.max(0.0, 6.0 - game.timeProgress), 2)));
866         game.objects.feather.rotation.z = Math.PI / 2.1 - 0.2 * windStrength + 1.45 * Math.max(0.0, game.timeProgress - 5.0);
867         game.objects.feather.rotation.x = Math.PI + Math.max(0.0, game.timeProgress - 4.5) * Math.sin(Math.pow(game.timeProgress - 4.5, 2));
868       }
869       if(game.timeProgress > 7.0) {
870         game.ui.root.querySelectorAll('.ui-page.gameplay p').forEach((elem) => {
871           let opacity = Math.max(0.0, Math.min(1.0, 8.0 - game.timeProgress));
872           elem.style.opacity = opacity.toFixed(2);
873         });
874       }
875       cameraSwayFactor = cameraSwayFactor * (1 - (game.timeProgress / 8));
876       cameraX = -5 + Math.pow(Math.max(0, game.timeProgress - 3) / 5, 1.6) * 5;
878       if(game.timeProgress > 6.0 && game.timeProgress < 7.0 && game.settings['controls'] != 'mouse') {
879         game.controls.positionX = 0;
880         game.controls.positionY = -3;
881       }
882       game.objects.pinwheel.material[4].opacity = game['fn'].easeInOut(Math.max(0, (game.timeProgress - 7)));
883       if(game.timeProgress >= 8.0) {
884         game.ui.root.querySelectorAll('.ui-page.gameplay p').forEach((elem) => {
885           let opacity = Math.max(0.0, Math.min(1.0, 8.0 - game.timeProgress));
886           elem.style.opacity = opacity.toFixed(2);
887         });
888         game.view.music.offset = 0;
889         if(!game.view.muted) {
890           game.view.music.play();
891         }
892         game['fn'].moveToPage('gameplay', true);
893       }
894     } else if(game.ui.currentPage == 'endingcutscene') {
895       cameraX = -5;
896       cameraY = 0;
897       cameraSwayFactor = cameraSwayFactor * game.timeProgress / 8;
898       cameraX = 5 - Math.pow(Math.max(0, 5 - game.timeProgress) / 5, 1.6) * 5;
899       let trajectoryLerpValue = game['fn'].easeInOut(Math.min(6.0, game.timeProgress) / 6);
900       game.var.endingEntryTrajectory.addScaledVector(game.objects.feather.speed, delta);
901       game.var.endingExitTrajectory.setX(11.2 * game['fn'].easeInOut(Math.min(1, 1 - Math.max(0, 4 - game.timeProgress) / 4)));
902       game.var.endingExitTrajectory.setY(-game.courseRadius - 7.6 * game['fn'].easeInOut(Math.min(1, 1 - Math.max(0, 4 - game.timeProgress) / 4)));
903       game.var.endingExitTrajectory.setZ(-8.9 * game['fn'].easeInOut(Math.min(1, 1 - Math.max(0, 4 - game.timeProgress) / 4)));
904       game.objects.feather.rotation.x = game['fn'].lerp(game.var.endingEntryRotation.x, game.var.endingExitRotation.x, trajectoryLerpValue);
905       game.objects.feather.rotation.y = game['fn'].lerp(game.var.endingEntryRotation.y, game.var.endingExitRotation.y, trajectoryLerpValue);
906       game.objects.feather.rotation.z = game['fn'].lerp(game.var.endingEntryRotation.z, game.var.endingExitRotation.z, trajectoryLerpValue);
907       game.objects.feather.position.lerpVectors(game.var.endingEntryTrajectory, game.var.endingExitTrajectory, trajectoryLerpValue);
908       game.objects.pinwheel.material[4].opacity = game['fn'].easeInOut(Math.max(0, (1 - game.timeProgress)));
909       if(!game.settings['highcontrast']) {
910         let letterScale = game['fn'].lerp(0.3, 0.0, game['fn'].easeInOut(Math.max(0, Math.min(1, game.timeProgress - 6))));
911         for(let i = 0; i < game.objects.words.length; i++) {
912           let word = game.objects.words[i];
913           if(!word.collected) {
914             continue;
915           }
916           let x, y, z;
917           let collectionAnimationDuration = 1.0;
918           for(let j = 0; j < word.children.length; j++) {
919             let letter = word.children[j];
920             let animationProgress = (((game.timeProgress + 5 * word.randomAnimOffset) % 5) / 5 + j / 37) % 1;
921             x = game.objects.feather.scale.x * 0.5 * Math.cos(animationProgress * 1 * Math.PI * 2);
922             y = 0.2 * Math.sin(animationProgress * 7 * Math.PI * 2);
923             z = 0.2 * Math.cos(animationProgress * 7 * Math.PI * 2);
924             x = x * Math.cos(game.objects.feather.rotation.z) - y * Math.sin(game.objects.feather.rotation.z);
925             y = y * Math.cos(game.objects.feather.rotation.z) + x * Math.sin(game.objects.feather.rotation.z);
926             x += game.objects.feather.position.x - word.position.x;
927             y += game.objects.feather.position.y - word.position.y;
928             z += game.objects.feather.position.z - word.position.z;
929             if(i == 0 && !word.collected) {
930               // If we don't catch this edge case here, the manually placed first word might be visible
931               // in the closing cutscene if it is not collected.
932               x = 9999;
933             }
934             letter.position.set(x, y, z);
935             let rotation = (game.timeProgress * 3 + 2 * Math.PI * word.randomAnimOffset) % (2 * Math.PI);
936             letter.rotation.set(rotation + j, rotation + 2*j, rotation + 3*j);
937             letter.scale.set(letterScale, letterScale, letterScale);
938           }
939         }
940       }
941       if(game.timeProgress >= 8) {
942         game.ui.root.querySelector('.ui-page.title').classList.add('end');
943         game['fn'].moveToPage('outro', true);
944       }
945     } else if(game.ui.reachedEnd) {
946       cameraX = 5;
947       cameraY = 0;
948     }
949     if(typeof(cameraX) == 'number' && typeof(cameraY) == 'number') {
950       game.view.camera.position.setY(cameraY - game.courseRadius + 0.07 * cameraSwayFactor * Math.sin(game.view.clock.getElapsedTime() * 0.5));
951       game.view.camera.position.setX(cameraX + 0.05 * cameraSwayFactor * Math.sin(game.view.clock.getElapsedTime() * 0.7));
952     }
953     game.view.renderer.render(scene, game.view.camera);
954     return;
955   }
956   if(game.settings['enablehud']) {
957     if(game.timeProgress < 0.5) {
958       game.ui.hud.style.opacity = Math.min(1, game.timeProgress * 4).toFixed(2);
959     }
960     const failsafe = 0.0001;
961     const radiusOuter = 0.5;
962     const radiusInner = 0.4;
963     const progress = Math.max(failsafe, Math.min(1 - failsafe, game.timeProgress / game.timeTotal));
964     const xOuter = (0.5 + radiusOuter * Math.sin(progress * 2 * Math.PI)).toFixed(4);
965     const yOuter = (0.5 + radiusOuter * Math.cos(progress * 2 * Math.PI)).toFixed(4);
966     const xInner = (0.5 + radiusInner * Math.sin(progress * 2 * Math.PI)).toFixed(4);
967     const yInner = (0.5 + radiusInner * Math.cos(progress * 2 * Math.PI)).toFixed(4);
968     for(let segment of [0, 1]) {
969       let p = 'M' + xOuter + ',' + yOuter;
970       p += 'A' + radiusOuter + ',' + radiusOuter + ' 0 ' + ((progress >= 0.5) ? (1 - segment) : segment) + ' ' + (1 - segment) + ' .5,' + (0.5 + radiusOuter);
971       p += 'V' + (0.5 + radiusInner);
972       p += 'A' + radiusInner + ',' + radiusInner + ' 0 ' + ((progress >= 0.5) ? (1 - segment) : segment) + ' ' + segment + ' ' + xInner + ',' + yInner;
973       p += 'z';
974       game.ui.hud.children[0].children[segment].setAttribute('d', p);
975     }
976     if(game.timeProgress > game.timeTotal - 0.5) {
977       game.ui.hud.style.opacity = Math.max(0, (game.timeTotal - game.timeProgress - 0.25) * 4).toFixed(2);
978     }
979   }
980   if(game.ui.root.querySelector('.ui-page.gameplay p')) {
981     game.ui.root.querySelectorAll('.ui-page.gameplay p').forEach(elem => elem.remove());
982   }
983   if(game.timeProgress / game.timeTotal >= 1.0) {
984     game.ui.reachedEnd = true;
985     game.var.endingEntryTrajectory.set(game.objects.feather.position.x, game.objects.feather.position.y, game.objects.feather.position.z);
986     game.var.endingEntryRotation.x = game.objects.feather.rotation.x;
987     game.var.endingEntryRotation.y = game.objects.feather.rotation.y;
988     game.var.endingEntryRotation.z = game.objects.feather.rotation.z;
989     game.var.endingExitRotation.set(-0.2, 0, -0.2);
990     game['fn'].moveToPage('endingcutscene', true);
991   }
993   if(game.settings['audio']['music'] > 0.0 && game.view.music && !game.view.music.isPlaying) {
994     const remainingRealTime = (game.timeTotal - game.timeProgress) / (game.settings['difficulty']['speed'] / 100);
995     if(remainingRealTime >= game.assets['audio']['music-' + game.settings['audio']['theme']].duration - 2) {
996       game.view.music.offset = 0;
997       if(!game.view.muted) {
998         game.view.music.play();
999       }
1000     }
1001   }
1003   const angle = 2 * Math.PI * (game.timeProgress / game.timeTotal);
1004   game.view.camera.position.x = game.courseRadius * Math.sin(angle);
1005   game.view.camera.position.y = - game.courseRadius * Math.cos(angle);
1007   if(!game.settings['highcontrast']) {
1008     let sunsetValue = 2.0;
1009     if(!game.ui.reachedEnd) {
1010       sunsetValue = sunsetValue * game['fn'].easeInOut(Math.min(1, Math.max(0, ((game.timeProgress / game.timeTotal) - 0.3) / 0.6)));
1011     }
1012     if(game.settings['graphics'] <= 2) {
1013       for(let i = 0; i < 6; i++) {
1014         game.view.materials['cloud' + i].uniforms.lerp.value = sunsetValue;
1015       }
1016     } else {
1017       let cloudMaterialVariant = null;
1018       if(sunsetValue < 0.5 && !game.objects.clouds.children[0].material.name.endsWith('a')) {
1019         cloudMaterialVariant = 'a';
1020       } else if(sunsetValue >= 0.5 && sunsetValue < 1.5 && !game.objects.clouds.children[0].material.name.endsWith('b')) {
1021         cloudMaterialVariant = 'b';
1022       } else if(sunsetValue >= 1.5 && !game.objects.clouds.children[0].material.name.endsWith('c')) {
1023         cloudMaterialVariant = 'c';
1024       }
1025       if(cloudMaterialVariant) {
1026         for(let cloud of game.objects.clouds.children) {
1027           cloud.material = game.view.materials[cloud.material.name.slice(0, -1) + cloudMaterialVariant];
1028         }
1029         game.objects.backdrop.material = game.view.materials['cloud0' + cloudMaterialVariant];
1030       }
1031     }
1032   }
1034   if(game.timeProgress / game.timeTotal > 0.5 && game.objects.dayHouse.parent == scene) {
1035     scene.remove(game.objects.dayHouse);
1036     scene.add(game.objects.eveningHouse);
1037   }
1039   game.var.featherLocalPos.subVectors(game.objects.feather.position, game.view.camera.position).setZ(0);
1040   game.var.featherBorderForce.set(0, 0, 0);
1041   for(let coord of [0, 1]) {
1042     if(Math.abs(game.var.featherLocalPos.getComponent(coord)) > 3) {
1043       game.var.featherBorderForce.setComponent(coord, 3 * Math.sign(game.var.featherLocalPos.getComponent(coord)) - game.var.featherLocalPos.getComponent(coord));
1044     }
1045   }
1046   game['fn'].applyForceToFeather(game.var.featherBorderForce);
1047   const tiltedGravity = game.gravity.clone();
1048   game.var.pinwheelDistance.subVectors(game.objects.feather.position, game.objects.pinwheel.position).setZ(0);
1050   const pinwheelRotationTargetSpeed = 1 + Math.max(0, 2 - game.var.pinwheelDistance.length());
1051   game.var.pinwheelRotationSpeed = Math.max(1, pinwheelRotationTargetSpeed, game.var.pinwheelRotationSpeed - 2 * delta);
1052   game.objects.pinwheel.rotation.z -= game.var.pinwheelRotationSpeed * 5 * delta;
1053   game.objects.pinwheel.position.x = game.view.camera.position.x + game.controls.positionX;
1054   game.objects.pinwheel.position.y = game.view.camera.position.y + game.controls.positionY;
1056   const pinwheelForce = 0.5 * Math.max(0, Math.pow(game.var.pinwheelDistance.length(), - 0.5) - 0.5);
1057   game['fn'].applyForceToFeather(game.var.pinwheelDistance.normalize().multiplyScalar(pinwheelForce));
1058   if(pinwheelForce < 0.2) {
1059     if(game.objects.feather.swayDirection > 0 && game.objects.feather.speed.x > 1.5) {
1060       game.objects.feather.swayDirection *= -1;
1061     } else if(game.objects.feather.swayDirection < 0 && game.objects.feather.speed.x < -1.5) {
1062       game.objects.feather.swayDirection *= -1;
1063     }
1064     tiltedGravity.x += game.objects.feather.swayDirection;
1065   }
1066   if(game.objects.feather.speed.y > -1) {
1067     game['fn'].applyForceToFeather(tiltedGravity);
1068   }
1069   game.objects.feather.rotation.z = -0.1 * game.objects.feather.speed.x * game.settings['difficulty']['speed'] / 100;
1070   game.objects.feather.position.addScaledVector(game.objects.feather.speed, delta * game.settings['difficulty']['speed'] / 100);
1072   if(pinwheelForce > 0.2) {
1073     if(game.objects.feather.twistSpeed < 0.0001) {
1074       game.objects.feather.twistSpeed = (Math.random() - 0.5) * 0.01;
1075     }
1076     game.objects.feather.twistSpeed = Math.sign(game.objects.feather.twistSpeed) * 0.1 * game.objects.feather.speed.length();
1077   } else {
1078     game.objects.feather.twistSpeed = 0.98 * game.objects.feather.twistSpeed;
1079     if(Math.abs(game.objects.feather.twistSpeed < 0.1)) {
1080       let rotationDelta = game.objects.feather.rotation.x;
1081       if(rotationDelta >= Math.PI) {
1082         rotationDelta -= 2 * Math.PI;
1083       }
1084       game.objects.feather.twistSpeed -= rotationDelta * 0.02;
1085     }
1086   }
1088   game.objects.feather.twistSpeed = Math.min(0.13, game.objects.feather.twistSpeed) * game.settings['difficulty']['speed'] / 100;
1089   game.objects.feather.rotation.x = (game.objects.feather.rotation.x + game.objects.feather.twistSpeed) % (2 * Math.PI);
1091   let collectedScale = 0.0;
1092   if(!game.settings['highcontrast'] && game.settings['graphics'] <= 2) {
1093     collectedScale = game['fn'].lerp(0.6, 0.3, 1 - Math.pow(1 - game.objects.words.collectedCount / game.objects.words.length, 2));
1094   } else if(!game.settings['highcontrast'] && game.settings['graphics'] == 3) {
1095     collectedScale = 0.3;
1096   }
1097   const collectingRadius = - 0.5 + 1.5 * game.settings['difficulty']['collectingradius'];
1098   for(let i = 0; i < game.objects.words.length; i++) {
1099     let word = game.objects.words[i];
1100     if(!word.collected && new THREE.Vector3().subVectors(word.position, game.objects.feather.position).length() < collectingRadius) {
1101       word.collected = game.view.clock.getElapsedTime();
1102       game.objects.words.collectedCount += 1;
1103       game.ui.hud.children[1].innerText = game.objects.words.collectedCount;
1104       game['fn'].playRandomSound();
1105     }
1106     if(word.parent != game.view.scene) {
1107       // All that happens in here is the positional animation for the word, which
1108       // we can skip if it is no longer visible.
1109       continue;
1110     }
1111     let x, y, z;
1112     let collectionAnimationDuration = 1.0;
1113     for(let j = 0; j < word.children.length; j++) {
1114       game.var.notCollectedPos.set(0, 0, 0);
1115       game.var.collectedPos.set(0, 0, 0);
1116       let letter = word.children[j];
1117       let animationProgress = (((game.timeProgress + 5 * word.randomAnimOffset) % 5) / 5 + j / 37) % 1;
1118       if(!word.collected || game.view.clock.getElapsedTime() - word.collected <= collectionAnimationDuration) {
1119         x = word.position.x;
1120         y = word.position.y;
1121         z = 0;
1122         if(game.settings['graphics'] <= 2 && !game.settings['highcontrast']) {
1123           const wordAnimationRadius = 0.2;
1124           x += wordAnimationRadius * Math.cos(animationProgress * 5 * Math.PI * 2);
1125           y += wordAnimationRadius * Math.sin(animationProgress * 4 * Math.PI * 2);
1126           z += wordAnimationRadius * Math.sin(animationProgress * 6 * Math.PI * 2);
1127         }
1128         game.var.notCollectedPos.set(x, y, z);
1129       }
1130       if(word.collected) {
1131         if(!game.settings['highcontrast']) {
1132           x = game.objects.feather.scale.x * 0.5 * Math.cos(animationProgress * 1 * Math.PI * 2);
1133           y = 0.2 * Math.sin(animationProgress * 7 * Math.PI * 2);
1134           z = 0.2 * Math.cos(animationProgress * 7 * Math.PI * 2);
1135           x = x * Math.cos(game.objects.feather.rotation.z) - y * Math.sin(game.objects.feather.rotation.z);
1136           y = y * Math.cos(game.objects.feather.rotation.z) + x * Math.sin(game.objects.feather.rotation.z);
1137           x += game.objects.feather.position.x;
1138           y += game.objects.feather.position.y;
1139           z += game.objects.feather.position.z;
1140         } else {
1141           x = game.objects.feather.position.x;
1142           y = game.objects.feather.position.y;
1143           z = game.objects.feather.position.z;
1144         }
1145         game.var.collectedPos.set(x, y, z);
1146       }
1147       if(game.var.notCollectedPos.length() > 0 && game.var.collectedPos.length() > 0) {
1148         let collectingProgress = game['fn'].easeInOut(Math.max(0.0, Math.min(1.0, (game.view.clock.getElapsedTime() - word.collected) / collectionAnimationDuration)));
1149         letter.position.lerpVectors(game.var.notCollectedPos, game.var.collectedPos, collectingProgress);
1150         let scale = game['fn'].lerp(1.0, collectedScale, collectingProgress);
1151         letter.scale.set(scale, scale, scale);
1152       } else if(game.var.notCollectedPos.length() > 0) {
1153         letter.position.set(game.var.notCollectedPos.x, game.var.notCollectedPos.y, game.var.notCollectedPos.z);
1154       } else if(game.var.collectedPos.length() > 0) {
1155         letter.position.set(game.var.collectedPos.x, game.var.collectedPos.y, game.var.collectedPos.z);
1156         if(game.settings['highcontrast']) {
1157           // Special case because in high contrast mode, collected words vanish entirely.
1158           game.view.scene.remove(word);
1159         }
1160       }
1161       letter.position.sub(word.position);
1162       if(!game.settings['highcontrast']) {
1163         let rotation = (game.timeProgress * 3 + 2 * Math.PI * word.randomAnimOffset) % (2 * Math.PI);
1164         letter.rotation.set(rotation + j, rotation + 2*j, rotation + 3*j);
1165       }
1166     }
1167   }
1169   game.view.renderer.render(scene, game.view.camera);
1172 game['fn'].loadSettings = () => {
1173   let settings = {
1174     'controls': null, // set during first time launch depending on device
1175     'virtualinputleft': false,
1176     'enablehud': false,
1177     'graphics': 1,
1178     'audio': {
1179       'music': 0.5,
1180       'sounds': 0.5,
1181       'theme': null, // actual default value determined after asset loading
1182     },
1183     'feather': 'blue',
1184     'unlocks': [],
1185     'highcontrast': false,
1186     'font': 'standard',
1187     'difficulty': {
1188       'collectingradius': 1,
1189       'speed': 100,
1190     },
1191     'keyboard': {
1192       'up': ['ArrowUp', 'w'],
1193       'right': ['ArrowRight', 'd'],
1194       'down': ['ArrowDown', 's'],
1195       'left': ['ArrowLeft', 'a'],
1196       'tapmode': false,
1197     },
1198   };
1199   let stored;
1200   try {
1201     stored = window['localStorage'].getItem('upInTheAirGameSettings');
1202     game.ui.root.querySelector('.ui-page.options .warning.storage').style.display = 'none';
1203   } catch(error) {
1204     game.ui.root.querySelector('.ui-page.options .warning.storage').style.display = 'block';
1205   }
1206   if(stored) {
1207     let merge = (source, target) => {
1208       for(let k of Object.keys(source)) {
1209         if(source[k] != null && typeof(source[k]) == 'object' && typeof(target[k]) == 'object' && !Array.isArray(target[k])) {
1210           merge(source[k], target[k]);
1211         } else if(k in target) {
1212           target[k] = source[k];
1213         }
1214       }
1215     };
1216     stored = JSON.parse(stored);
1217     merge(stored, settings);
1218   }
1219   const ui = game.ui.root.querySelector('.ui-page.options');
1220   if(settings['controls']) {
1221     ui.querySelector('.controls input[value="' + settings['controls'] + '"]').checked = true;
1222     ui.querySelector('.controls .leftside input').checked = settings['virtualinputleft'];
1223     ui.querySelector('.controls .leftside').style.display = (['touchpad', 'thumbstick'].includes(settings['controls'])) ? 'block' : 'none';
1224     ui.querySelectorAll('.controls p span:not(.' + settings['controls'] + ')').forEach(span => span.style.display = 'none');
1225     ui.querySelector('.controls span.' + settings['controls']).style.display = 'block';
1226   }
1227   ui.querySelector('.hud input[name="upInTheAirGame-hud"]').checked = settings['enablehud'];
1228   game.ui.hud.style.display = settings['enablehud'] ? 'flex' : 'none';
1229   ui.querySelector('.graphics input[value="' + settings['graphics'] + '"]').checked = true;
1230   for(let audioCategory of ['music', 'sounds']) {
1231     let newValue = Math.max(0, Math.min(100, Math.round(100 * settings['audio'][audioCategory])));
1232     game.ui.root.querySelectorAll('.ui-page .audio input[type=range].' + audioCategory).forEach((elem) => {
1233       elem.value = newValue;
1234       elem.parentNode.nextElementSibling.innerText = newValue;
1235     });
1236   }
1237   let audioThemeRadio = ui.querySelector('.audiotheme input[value="' + settings['audio']['theme'] + '"]');
1238   if(audioThemeRadio) {
1239     audioThemeRadio.checked = true;
1240   }
1241   // Custom hash function that ensures our unlockables get stored in the same order,
1242   // regardless of the order in which they get unlocked.
1243   let miniHash = (input) => {
1244     return 4 * input.charCodeAt(0) + 0.1 * input.charCodeAt(1) + 3 * input.charCodeAt(2) + 2 * input.charCodeAt(3);
1245   }
1246   settings['unlocks'].sort((u1, u2) => miniHash(u1) > miniHash(u2));
1247   for(let unlockedFeather of settings['unlocks']) {
1248     if(!game.ui.root.querySelector('.ui-page.options .feather input[value="' + unlockedFeather + '"]')) {
1249       let radio = document.createElement('input');
1250       radio.type = 'radio';
1251       radio.name = 'upInTheAirGame-feather';
1252       radio.value = unlockedFeather;
1253       let img = document.createElement('img');
1254       if(unlockedFeather == 'golden' || unlockedFeather == 'ghost') {
1255         img.src = game['deploymentOptions']['assetUrlPrefix'] + 'textures/feather-' + unlockedFeather + '.png';
1256       } else {
1257         let unlock = game['fn'].unlockWithKey('NIbp2kW5' + unlockedFeather + 'e2ZDFl5Y');
1258         if(unlock && unlock['type'] == 'feather') {
1259           img.src = unlock['url'];
1260         } else {
1261           continue;
1262         }
1263       }
1264       img.alt = unlockedFeather[0].toUpperCase() + unlockedFeather.slice(1) + ' feather';
1265       let label = document.createElement('label');
1266       label.appendChild(radio);
1267       label.appendChild(img);
1268       game.ui.root.querySelector('.ui-page.options .feather').appendChild(label);
1269     }
1270   }
1271   if(!ui.querySelector('.feather input[value="' + settings['feather'] + '"]')) {
1272     settings['feather'] = 'blue';
1273   }
1274   ui.querySelector('.feather input[value=' + settings['feather'] + ']').checked = true;
1275   ui.querySelector('input[value="highcontrast"]').checked = !!settings['highcontrast'];
1276   ui.querySelector('.font input[value=' + settings['font'] + ']').checked = true;
1277   ui.querySelector('.difficulty select.collectingradius option[value="' + settings['difficulty']['collectingradius'] + '"]').selected = true;
1278   ui.querySelector('.difficulty select.speed option[value="' + settings['difficulty']['speed'] + '"]').selected = true;
1279   for(let direction of ['up', 'right', 'down', 'left']) {
1280     let keys = settings['keyboard'][direction];
1281     let btn = ui.querySelector('.keyboard button.' + direction);
1282     btn.value = keys.join('|');
1283     keys = keys.map(k => {
1284       if(k.length == 1 && k != 'ß') {
1285         k = k.toUpperCase();
1286       }
1287       switch(k) {
1288         case 'ArrowUp': return '🠕';
1289         case 'ArrowRight': return '🠖';
1290         case 'ArrowDown': return '🠗';
1291         case 'ArrowLeft': return '🠔';
1292         case ' ': return 'Space';
1293         default: return k;
1294       }
1295     });
1296     btn.innerText = keys.join(' or ');
1297   }
1298   ui.querySelector('input[value="tapmode"]').checked = !!settings['keyboard']['tapmode'];
1299   game.settings = settings;
1302 game['fn'].applySettings = () => {
1303   const ui = game.ui.root.querySelector('.ui-page.options');
1304   if(ui.querySelector('input[name="upInTheAirGame-controls"]:checked')) {
1305     game.settings['controls'] = ui.querySelector('input[name="upInTheAirGame-controls"]:checked').value;
1306   }
1307   game.settings['virtualinputleft'] = ui.querySelector('.controls .leftside input').checked;
1308   if(game.settings['virtualinputleft']) {
1309     game.ui.root.parentNode.classList.add('virtual-input-left');
1310   } else {
1311     game.ui.root.parentNode.classList.remove('virtual-input-left');
1312   }
1313   const virtualInput = game.ui.root.parentNode.querySelector('.virtual-input-widget');
1314   virtualInput.children[0].style.display = 'block';
1315   virtualInput.children[0].style.left = '50%';
1316   virtualInput.children[0].style.top = '50%';
1317   delete virtualInput.inProgress;
1318   if(game.settings['controls'] == 'touchpad') {
1319     virtualInput.classList.remove('thumbstick');
1320     virtualInput.classList.add('touchpad');
1321     game.ui.root.classList.remove('control-mouse', 'control-thumbstick');
1322     game.ui.root.classList.add('control-touchpad');
1323     virtualInput.children[0].style.display = 'none';
1324   } else if(game.settings['controls'] == 'thumbstick') {
1325     virtualInput.classList.remove('touchpad');
1326     virtualInput.classList.add('thumbstick');
1327     game.ui.root.classList.remove('control-mouse', 'control-touchpad');
1328     game.ui.root.classList.add('control-thumbstick');
1329   } else if(game.settings['controls'] == 'mouse') {
1330     virtualInput.classList.remove('touchpad', 'thumbstick');
1331     game.ui.root.classList.remove('control-touchpad', 'control-thumbstick');
1332     game.ui.root.classList.add('control-mouse');
1333   } else {
1334     virtualInput.classList.remove('touchpad', 'thumbstick');
1335     game.ui.root.classList.remove('control-mouse', 'control-touchpad', 'control-thumbstick');
1336   }
1337   for(let timeout of [10, 100, 1000]) {
1338     setTimeout(() => { game.ui.root.style.fontSize = (game.ui.root.clientWidth / 48) + 'px'; }, timeout);
1339   }
1340   game.settings['graphics'] = parseInt(ui.querySelector('input[name="upInTheAirGame-graphics"]:checked').value, 10);
1341   if(game.view) {
1342     let resolution = Math.round(3200 / Math.pow(2, game.settings['graphics']));
1343     game.view.canvas.width = resolution;
1344     game.view.canvas.height = resolution;
1345     game.view.camera.updateProjectionMatrix();
1346     game.view.renderer.setSize(game.view.canvas.width, game.view.canvas.height);
1347   }
1348   game.settings['enablehud'] = ui.querySelector('.hud input[name="upInTheAirGame-hud"]').checked;
1349   for(let audioCategory of ['music', 'sounds']) {
1350     game.settings['audio'][audioCategory] = parseInt(ui.querySelector('.audio input[type=range].' + audioCategory).value, 10) / 100;
1351   }
1352   let audioThemeRadio = ui.querySelector('.audiotheme input[name="upInTheAirGame-audiotheme"]:checked');
1353   if(audioThemeRadio) {
1354     game.settings['audio']['theme'] = audioThemeRadio.value;
1355   }
1356   game.settings['feather'] = ui.querySelector('input[name="upInTheAirGame-feather"]:checked').value;
1357   game.settings['highcontrast'] = ui.querySelector('input[value="highcontrast"]').checked;
1358   game.settings['font'] = ui.querySelector('input[name="upInTheAirGame-font"]:checked').value;
1359   game.settings['difficulty']['collectingradius'] = parseInt(ui.querySelector('.difficulty select.collectingradius').value, 10);
1360   game.settings['difficulty']['speed'] = parseInt(ui.querySelector('.difficulty select.speed').value, 10);
1361   for(let direction of ['up', 'right', 'down', 'left']) {
1362     game.settings['keyboard'][direction] = ui.querySelector('.keyboard button.' + direction).value.split('|');
1363   }
1364   game.settings['keyboard']['tapmode'] = ui.querySelector('input[value="tapmode"]').checked;
1365   try {
1366     window['localStorage'].setItem('upInTheAirGameSettings', JSON.stringify(game.settings));
1367     game.ui.root.querySelector('.ui-page.options .warning.storage').style.display = 'none';
1368   } catch(error) {
1369     game.ui.root.querySelector('.ui-page.options .warning.storage').style.display = 'block';
1370   }
1372   for(let audioCategory of ['music', 'sounds']) {
1373     game.settings['audio'][audioCategory] = parseInt(ui.querySelector('.audio input[type=range].' + audioCategory).value, 10) / 100;
1374     let value = Math.round(100 * game.settings['audio'][audioCategory]);
1375     game.ui.root.querySelectorAll('.ui-page .audio input[type=range].' + audioCategory).forEach((elem) => {
1376       elem.value = value;
1377       elem.parentNode.nextElementSibling.innerText = value;
1378     });
1379     if(audioCategory == 'music' && game.view && game.view.music) {
1380       game.view.music.setVolume(game.settings['audio'][audioCategory]);
1381     }
1382   }
1383   game.ui.root.classList.remove('font-atkinson', 'font-opendyslexic');
1384   if(game.settings['font'] != 'standard') {
1385     game.ui.root.classList.add('font-' + game.settings['font']);
1386   }
1389 game['fn'].createFeather = () => {
1390   let position, rotation;
1391   if(game.objects.feather) {
1392     position = game.objects.feather.position;
1393     rotation = game.objects.feather.rotation;
1394     game.objects.feather.geometry.dispose();
1395     game.objects.feather.material.dispose();
1396     game.view.scene.remove(game.objects.feather);
1397     delete game.objects.feather;
1398   }
1400   const featherGeometry = new THREE.PlaneGeometry(1.6, 0.5);
1401   let options = {
1402     map: game.assets.textures['feather-' + game.settings['feather']],
1403     transparent: true,
1404     alphaTest: 0.01,
1405     side: THREE.DoubleSide,
1406   }
1407   if(game.settings['feather'] == 'golden') {
1408     options.color = 0xffffff;
1409     options.emissive = 0x644a1e;
1410     options.roughness = 0.5;
1411     options.metalness = 0.4;
1412   }
1413   if(game.settings['feather'] == 'ghost') {
1414     options.opacity = 0.7;
1415   }
1416   game.view.materials.feather = new THREE.MeshStandardMaterial(options);
1417   game.objects.feather = new THREE.Mesh(featherGeometry, game.view.materials.feather);
1418   game.objects.feather.rotation.order = 'ZXY';
1419   if(position) {
1420     game.objects.feather.position.set(position.x, position.y, position.z);
1421   }
1422   if(rotation) {
1423     game.objects.feather.rotation.set(rotation.x, rotation.y, rotation.z);
1424   }
1425   game.view.scene.add(game.objects.feather);
1426   game.objects.feather.speed = new THREE.Vector3(0, 0, 0);
1427   game.gravity = new THREE.Vector3(0, -0.1, 0);
1428   game.objects.feather.swayDirection = 0.2;
1429   game.objects.feather.twistSpeed = 0.1;
1432 game['fn'].createMeshes = () => {
1433   if(game.objects.clouds && game.objects.clouds.parent == game.view.scene) {
1434     game.view.scene.remove(game.objects.clouds);
1435     if(game.objects.clouds.children.length > 0) {
1436       game.objects.clouds.children[0].geometry.dispose();
1437     }
1438     for(let mKey in game.view.materials) {
1439       game.view.materials[mKey].dispose();
1440     }
1441     delete game.objects.clouds;
1442   }
1443   if(game.objects.backdrop && game.objects.backdrop.parent == game.view.scene) {
1444     game.view.scene.remove(game.objects.backdrop);
1445     game.objects.backdrop.material.dispose();
1446     game.objects.backdrop.geometry.dispose();
1447   }
1448   if(game.assets.fonts.geometry) {
1449     for(let geom of Object.values(game.assets.fonts.geometry)) {
1450       if(geom.customMaterial) {
1451         geom.customMaterial.dispose();
1452       }
1453       geom.dispose();
1454     }
1455     delete game.assets.fonts.geometry;
1456   }
1457   if(game.view.materials) {
1458     for(let material of Object.values(game.view.materials)) {
1459       material.dispose();
1460     }
1461     delete game.view.materials;
1462   }
1464   if(game.view.materials && game.view.materials.feather) {
1465     game.view.materials = {
1466       'feather': game.view.materials['feather'],
1467     };
1468   } else {
1469     game.view.materials = {};
1470   }
1472   if(!game.settings['highcontrast']) {
1473     let cloudShaders;
1474     let cloudGeometry = new THREE.PlaneGeometry(1, 200 / 350);
1475     if(game.settings['graphics'] <= 2) {
1476       cloudShaders = {
1477         vertexShader:
1478        `
1479        precision highp float;
1480        precision highp int;
1481        varying vec2 vUv;
1482        void main() {
1483          vUv = uv;
1484          gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
1485        }
1486          `,
1487         fragmentShader:
1488          `
1489        precision mediump float;
1490        uniform sampler2D texture1;
1491        uniform sampler2D texture2;
1492        uniform sampler2D texture3;
1493        uniform float lerp;
1494        varying vec2 vUv;
1495        void main() {
1496          if(lerp > 1.0) {
1497            vec4 col1 = texture2D(texture2, vUv);
1498            vec4 col2 = texture2D(texture3, vUv);
1499            gl_FragColor = mix(col1, col2, lerp - 1.0);
1500          } else {
1501            vec4 col1 = texture2D(texture1, vUv);
1502            vec4 col2 = texture2D(texture2, vUv);
1503            gl_FragColor = mix(col1, col2, lerp);
1504          }
1505          // I don't know how GLSL works: why do I need to do this to match the textures?
1506          gl_FragColor = mix(gl_FragColor, vec4(1.0, 1.0, 1.0, gl_FragColor.a), 0.5);
1507        }
1508          `
1509       };
1510     }
1511     for(let i = 0; i < 6; i++) {
1512       if(game.settings['graphics'] <= 2) {
1513         game.view.materials['cloud' + i] = new THREE.ShaderMaterial({
1514           uniforms: THREE.UniformsUtils.merge([{
1515             texture1: null,
1516             texture2: null,
1517             texture3: null,
1518             lerp: null,
1519           }]),
1520           ...cloudShaders,
1521         });
1522         game.view.materials['cloud' + i].uniforms.texture1.value = game.assets.textures['cloud' + i + 'a'];
1523         game.view.materials['cloud' + i].uniforms.texture2.value = game.assets.textures['cloud' + i + 'b'];
1524         game.view.materials['cloud' + i].uniforms.texture3.value = game.assets.textures['cloud' + i + 'c'];
1525         if(game.ui.reachedEnd) {
1526           game.view.materials['cloud' + i].uniforms.lerp.value = 2.0;
1527         } else {
1528           game.view.materials['cloud' + i].uniforms.lerp.value = 0.0;
1529         }
1530         game.view.materials['cloud' + i].transparent = true;
1531       } else {
1532         for(let variant of ['a', 'b', 'c']) {
1533           game.view.materials['cloud' + i + variant] = new THREE.MeshBasicMaterial({
1534             map: game.assets.textures['cloud' + i + variant],
1535             transparent: true,
1536             alphaTest: 0.5,
1537           });
1538           game.view.materials['cloud' + i + variant].name = 'cloud' + i + variant;
1539         }
1540       }
1541     }
1542     game.objects.clouds = new THREE.Group();
1543     let textureVariantSuffix = '';
1544     if(game.settings['graphics'] > 2) {
1545       if(game.ui.reachedEnd) {
1546         textureVariantSuffix = 'c';
1547       } else {
1548         textureVariantSuffix = 'a';
1549       }
1550     }
1551     game.view.materials.letter = new THREE.MeshStandardMaterial({
1552       color: 0xffffff,
1553       emissive: 0x606060,
1554       roughness: 0.4,
1555       metalness: 1,
1556     });
1557     if(game.settings['graphics'] <= 2) {
1558       game.assets.fonts.geometry = {};
1559       for(let letter of [...new Set(game.assets.wordList.join(''))]) {
1560         if(game.settings['graphics'] == 1) {
1561           game.assets.fonts.geometry[letter] = new TextGeometry(letter, {
1562             font: game.assets.fonts.cookie,
1563             size: 0.2,
1564             depth: 0.03,
1565             curveSegments: 2,
1566             bevelEnabled: false,
1567           });
1568           game.assets.fonts.geometry[letter].computeBoundingBox();
1569           let bbox = game.assets.fonts.geometry[letter].boundingBox;
1570           // Add these to local 0,0 later to get the letter's center rotation point
1571           game.assets.fonts.geometry[letter].dx = (bbox.max.x - bbox.min.x) / 2;
1572           game.assets.fonts.geometry[letter].dy = (bbox.max.y - bbox.min.y) / 2;
1573         } else {
1574           let letterCanvas = document.createElement('canvas');
1575           letterCanvas.width = 64;
1576           letterCanvas.height = 64;
1577           let letterCanvasContext = letterCanvas.getContext('2d');
1578           letterCanvasContext.font = '60px Cookie';
1579           letterCanvasContext.fillStyle = '#000';
1580           letterCanvasContext.fillRect(0, 0, letterCanvas.width, letterCanvas.height);
1581           letterCanvasContext.fillStyle = '#fff';
1582           let bbox = letterCanvasContext.measureText(letter);
1583           let vOffset = bbox.actualBoundingBoxAscent - 0.5 * (bbox.actualBoundingBoxAscent + bbox.actualBoundingBoxDescent);
1584           letterCanvasContext.fillText(letter, Math.round((letterCanvas.width - bbox.width) / 2), (letterCanvas.height / 2) + vOffset);
1585           let alphaMap = new THREE.CanvasTexture(letterCanvas);
1586           alphaMap.needsUpdate = true;
1587           let letterMaterial = new THREE.MeshStandardMaterial({
1588             color: game.view.materials.letter.color,
1589             emissive: 0x303030,
1590             roughness: game.view.materials.letter.roughness,
1591             metalness: game.view.materials.letter.metalness,
1592             side: THREE.DoubleSide,
1593             alphaMap: alphaMap,
1594             transparent: true,
1595           });
1596           game.assets.fonts.geometry[letter] = new THREE.PlaneGeometry(0.3, 0.3);
1597           game.assets.fonts.geometry[letter].dx = 0;
1598           game.assets.fonts.geometry[letter].dy = 0;
1599           game.assets.fonts.geometry[letter].customMaterial = letterMaterial;
1600         }
1601       }
1602       let numClouds = 300;
1603       if(game.settings['graphics'] == 2) {
1604         numClouds = 75;
1605       }
1606       for(let i = 0; i < numClouds; i++) {
1607         let randomAngle = Math.random() * 2 * Math.PI;
1608         let randomCameraX = game.courseRadius * Math.sin(randomAngle);
1609         let randomCameraY = game.courseRadius * Math.cos(randomAngle);
1610         let cloud = new THREE.Mesh(cloudGeometry, game.view.materials['cloud' + (i % 5 + 1) + textureVariantSuffix]);
1611         cloud.position.z = -15 - Math.round(Math.random() * 40);
1612         const vFOV = THREE.MathUtils.degToRad(game.view.camera.fov);
1613         let maxCameraDistance = 2 * Math.tan(vFOV / 2) * Math.abs(cloud.position.z - game.view.camera.position.z);
1614         cloud.position.x = randomCameraX + maxCameraDistance * 2 * (Math.random() - 0.5);
1615         cloud.position.y = randomCameraY + maxCameraDistance * 2 * (Math.random() - 0.5);
1616         let scale = 21 + (Math.random() * 0.5 + 0.5) * Math.abs(cloud.position.z);
1617         cloud.scale.set(scale, scale, scale);
1618         game.objects.clouds.add(cloud);
1619       }
1620     } else {
1621       const minimalLetterGeometry = new THREE.BoxGeometry(0.2, 0.2, 0.2);
1622       minimalLetterGeometry.dx = 0;
1623       minimalLetterGeometry.dy = 0;
1624       game.assets.fonts.geometry = {};
1625       for(let letter of [...new Set(game.assets.wordList.join(''))]) {
1626         game.assets.fonts.geometry[letter] = minimalLetterGeometry;
1627       }
1628       for(let r = 0; r < game.courseRadius / 3; r++) {
1629         let angle = THREE.MathUtils.degToRad(360 * 3 * r / game.courseRadius);
1630         let cameraX = game.courseRadius * Math.sin(angle);
1631         let cameraY = game.courseRadius * Math.cos(angle);
1632         const vFOV = THREE.MathUtils.degToRad(game.view.camera.fov);
1633         let z = -15;
1634         let maxCameraDistance = Math.tan(vFOV / 2) * Math.abs(z - game.view.camera.position.z);
1635         let axis = [-1, 0, 1];
1636         if(r % 2 == 0) {
1637           axis = [-0.5, 0.5];
1638         }
1639         for(let step of axis) {
1640           let shape = 1 + Math.floor(Math.random() * 5);
1641           let cloud = new THREE.Mesh(cloudGeometry, game.view.materials['cloud' + shape + textureVariantSuffix]);
1642           cloud.position.x = cameraX + step * 1.2 * maxCameraDistance * Math.sin(angle);
1643           cloud.position.y = cameraY + step * maxCameraDistance * Math.cos(angle);
1644           cloud.position.z = z;
1645           let scale = 15 + 0.5 * Math.abs(cloud.position.z);
1646           cloud.scale.set(scale, scale, scale);
1647           game.objects.clouds.add(cloud);
1648         }
1649       }
1650     }
1651     game.view.scene.add(game.objects.clouds);
1652     game.objects.backdrop = new THREE.Mesh(new THREE.PlaneGeometry(350, 350), game.view.materials['cloud0' + textureVariantSuffix]);
1653     game.objects.backdrop.position.setZ(-100);
1654   } else {
1655     game.view.materials.letter = new THREE.MeshStandardMaterial({
1656       color: 0x00ff00,
1657       emissive: 0x00ff00,
1658     });
1659     const highcontrastLetterGeometry = new THREE.SphereGeometry(0.1, 16, 16);
1660     highcontrastLetterGeometry.dx = 0;
1661     highcontrastLetterGeometry.dy = 0;
1662     game.assets.fonts.geometry = {};
1663     for(let letter of [...new Set(game.assets.wordList.join(''))]) {
1664       game.assets.fonts.geometry[letter] = highcontrastLetterGeometry;
1665     }
1666     const highContrastBackdropMaterial = new THREE.MeshBasicMaterial({
1667       map: game.assets.textures['highcontrast-backdrop'],
1668     });
1669     game.objects.backdrop = new THREE.Mesh(new THREE.PlaneGeometry(150, 150), highContrastBackdropMaterial);
1670     game.objects.backdrop.position.setZ(-10);
1671   }
1672   if(game.objects.words) {
1673     for(let word of game.objects.words) {
1674       game['fn'].prepareWordMesh(word);
1675     }
1676   }
1677   game.view.scene.add(game.objects.backdrop);
1680 game['fn'].unlockFeather = (feather, url) => {
1681   if(game.settings['unlocks'].includes(feather)) {
1682     return false;
1683   }
1684   game.settings['unlocks'].push(feather);
1685   if(!url) {
1686     url = game['deploymentOptions']['assetUrlPrefix'] + 'textures/feather-' + feather + '.png';
1687   } else if(url.startsWith('textures/')) {
1688     url = game['deploymentOptions']['assetUrlPrefix'] + url;
1689   }
1691   if(!game.assets['textures']['feather-' + feather]) {
1692     (new THREE.TextureLoader()).load(url, (result) => {
1693       result.colorSpace = THREE.SRGBColorSpace;
1694       result.minFilter = THREE.NearestFilter;
1695       result.magFilter = THREE.NearestFilter;
1696       result.repeat = new THREE.Vector2(1, -1);
1697       result.wrapT = THREE.RepeatWrapping;
1698       game.assets['textures']['feather-' + feather] = result;
1699     }, () => {}, (err) => {
1700       console.error('Error while loading ' + feather + ' feather texture: ' + err);
1701     });
1702   }
1703   // Custom hash function that ensures our unlockables get stored in the same order,
1704   // regardless of the order in which they get unlocked.
1705   let miniHash = (input) => {
1706     return 4 * input.charCodeAt(0) + 0.1 * input.charCodeAt(1) + 3 * input.charCodeAt(2) + 2 * input.charCodeAt(3);
1707   }
1708   game.settings['unlocks'].sort((u1, u2) => miniHash(u1) > miniHash(u2));
1709   let insertAfterFeather = 'purple';
1710   if(game.settings['unlocks'].indexOf(feather) >= 1) {
1711     insertAfterFeather = game.settings['unlocks'][game.settings['unlocks'].indexOf(feather) - 1];
1712   }
1713   let radio = document.createElement('input');
1714   radio.type = 'radio';
1715   radio.name = 'upInTheAirGame-feather';
1716   radio.value = feather;
1717   radio.addEventListener('change', () => {
1718     game['fn'].applySettings();
1719     game['fn'].createFeather();
1720   });
1721   let img = document.createElement('img');
1722   img.src = url;
1723   img.alt = feather[0].toUpperCase() + feather.slice(1) + ' feather';
1724   let label = document.createElement('label');
1725   label.appendChild(radio);
1726   label.appendChild(img);
1727   game.ui.root.querySelector('.ui-page.options .feather input[value="' + insertAfterFeather + '"]').parentNode.after(label);
1728   game['fn'].applySettings();
1729   let ui = game.ui.root.querySelector('.ui-page.unlock');
1730   let img2 = ui.querySelector('img');
1731   img2.src = img.src;
1732   img2.alt = img.alt;
1733   ui.querySelector('p.name').innerText = img2.alt;
1734   return true;
1737 game['fn'].moveToPage = (target, skipFade = false) => {
1738   let fadeDuration = 250;
1739   if(skipFade) {
1740     fadeDuration = 0;
1741   }
1742   // After the gameplay page is shown for the first time, always keep it around as a backdrop
1743   game.ui.root.querySelectorAll('.ui-page:not(.' + target + '):not(.gameplay)').forEach((page) => {
1744     page.style.opacity = '0';
1745     setTimeout((page) => {
1746       page.style.display = 'none';
1747     }, fadeDuration, page);
1748   });
1749   if(game.ui.currentPage == 'title' && !game.ui.reachedStart) {
1750     setTimeout(() => {
1751       game.ui.root.querySelector('.ui-page.title h1').removeAttribute('style');
1752       game.ui.root.querySelectorAll('.ui-page.title button').forEach(btn => { btn.disabled = false; btn.removeAttribute('style'); });
1753       game.ui.root.querySelector('.ui-page.title .footer').removeAttribute('style');
1754       game.ui.root.querySelector('.ui-page.title .system-buttons').removeAttribute('style');
1755       game.ui.reachedStart = true;
1756     }, fadeDuration);
1757   }
1758   if(target == 'title' && game.view) {
1759     game.view.cheatBuffer = '';
1760   }
1761   if(target == 'title' && (!game.ui.currentPage || ['loading', 'controls'].includes(game.ui.currentPage))) {
1762     game['fn'].initializeGame(game.ui.root.querySelector('canvas'));
1763   }
1764   if(target == 'title' && game.ui.root.querySelector('.ui-page.gameplay p')) {
1765     game.ui.root.querySelectorAll('.ui-page.gameplay p').forEach(elem => elem.remove());
1766   }
1767   if(target == 'title' && game.view && game.view.windSound && game.view.windSound.isPlaying) {
1768     game.view.windSound.stop();
1769   }
1770   if(target == 'title' && game.view && game.view.music && game.view.music.isPlaying) {
1771     game.view.music.stop();
1772     if(game.view.music.timeoutID) {
1773       clearTimeout(game.view.music.timeoutID);
1774       delete game.view.music.timeoutID;
1775     }
1776   }
1777   if((target != 'pause' && game.ui.currentPage != 'pause') || target == 'title') {
1778     game.ui.hud.style.opacity = '0';
1779   }
1780   if(target == 'outro') {
1781     if(game.view.music.isPlaying) {
1782       game.view.music.stop();
1783     }
1784     let collectedWords = game.objects.words.filter(w => w.collected).map(w => w.text);
1785     game.ui.root.querySelector('.ui-page.outro .count').innerText = game.objects.words.collectedCount;
1786     game.ui.root.querySelector('.ui-page.outro .optionalPlural').innerText = 'word' + ((game.objects.words.collectedCount == 1) ? '' : 's') + '.';
1787     let ratingElem = game.ui.root.querySelector('.ui-page.outro .rating');
1788     let exampleElems = game.ui.root.querySelectorAll('.ui-page.outro .examples');
1789     let finalParagraph = game.ui.root.querySelector('.ui-page.outro .area > p:last-child');
1790     ratingElem.style.display = 'none';
1791     exampleElems.forEach(elem => { elem.style.display = 'none'; });
1792     let returnButton = game.ui.root.querySelector('.ui-page.outro button.goto');
1793     if(game.objects.words.collectedCount == 100 || game.objects.words.collectedCount == 0) {
1794       finalParagraph.style.display = 'none';
1795       let neededUnlocking = false;
1796       if(game.objects.words.collectedCount == 100) {
1797         neededUnlocking = game['fn'].unlockFeather('golden');
1798       } else {
1799         neededUnlocking = game['fn'].unlockFeather('ghost');
1800       }
1801       if(neededUnlocking) {
1802         returnButton.innerText = 'Continue';
1803         returnButton.classList.remove('title');
1804         returnButton.classList.add('unlock');
1805       } else {
1806         returnButton.innerText = 'Return to Title Screen';
1807         returnButton.classList.remove('unlock');
1808         returnButton.classList.add('title');
1809       }
1810     } else {
1811       finalParagraph.style.display = 'block';
1812       returnButton.innerText = 'Return to Title Screen';
1813       returnButton.classList.remove('unlock');
1814       returnButton.classList.add('title');
1815     }
1816     if(game.objects.words.collectedCount > 0) {
1817       if(game.objects.words.collectedCount == 100) {
1818         ratingElem.style.display = 'block';
1819         ratingElem.innerText = 'Wow, you managed to collect all of them. Congratulations!';
1820       } else {
1821         let generateExampleSentences = (wordList) => {
1822           let container = game.ui.root.querySelector('.ui-page.outro div.examples');
1823           while(container.children.length > 0) {
1824             container.children[0].remove();
1825           }
1826           let words = {};
1827           for(let category of Object.keys(game.assets.words)) {
1828             words[category] = [];
1829             for(let word of game.assets.words[category]) {
1830               if(wordList.includes(word)) {
1831                 words[category].push(word);
1832               }
1833             }
1834           }
1835           let result = [];
1836           let failedAttempts = 0;
1837           while(result.length < 3 && failedAttempts < 1000) {
1838             let sentence = game.assets.sentences[Math.floor(Math.random() * game.assets.sentences.length)];
1839             while(sentence.indexOf('{') > -1) {
1840               let areWeStuck = true;
1841               for(let category of Object.keys(words)) {
1842                 if(sentence.includes('{' + category + '}')) {
1843                   if(words[category].length == 0) {
1844                     break;
1845                   }
1846                   let choice = words[category][Math.floor(Math.random() * words[category].length)];
1847                   if(category == 'sorry') {
1848                     if(choice == 'sorry') {
1849                       sentence = sentence.replace('{sorry}', 'I’m {sorry}');
1850                     }
1851                     if(choice == 'apologize') {
1852                       sentence = sentence.replace('{sorry}', 'I {sorry}');
1853                     }
1854                   }
1855                   if(sentence.indexOf('{' + category + '}') == 0) {
1856                     choice = choice[0].toUpperCase() + choice.slice(1);
1857                   }
1858                   sentence = sentence.replace('{' + category + '}', '<strong>' + choice + '</strong>');
1859                   words[category].splice(words[category].indexOf(choice), 1);
1860                   areWeStuck = false;
1861                 }
1862               }
1863               if(areWeStuck) {
1864                 break;
1865               }
1866             }
1867             if(sentence.indexOf('{') == -1 && !result.includes(sentence)) {
1868               result.push(sentence);
1869               failedAttempts = 0;
1870             }
1871             failedAttempts += 1;
1872           }
1873           for(let sentence of result) {
1874             let elem = document.createElement('p');
1875             elem.innerHTML = sentence;
1876             container.appendChild(elem);
1877           }
1878         };
1879         generateExampleSentences(collectedWords);
1880         game.ui.root.querySelector('.ui-page.outro button.examples').addEventListener('click', () => { generateExampleSentences(collectedWords); });
1881         exampleElems.forEach(elem => { elem.style.display = 'flex'; });
1882       }
1883     } else {
1884       ratingElem.style.display = 'block';
1885       ratingElem.innerText = 'You completed the course while dodging every word. That’s an achievement all on its own. Respect!';
1886     }
1887   }
1888   if(target == 'options') {
1889     game.ui.root.querySelectorAll('.options .areatabs button').forEach((btn) => {
1890       if(btn.classList.contains('general')) {
1891         btn.classList.add('active');
1892       } else {
1893         btn.classList.remove('active');
1894       }
1895     });
1896     game.ui.root.querySelectorAll('.options > div.area.twocol').forEach((area) => {
1897       if(area.classList.contains('general')) {
1898         area.style.display = 'flex';
1899       } else {
1900         area.style.display = 'none';
1901       }
1902     });
1903   }
1904   const targetElems = [game.ui.root.querySelector('.ui-page.' + target + '')];
1905   if(game.ui.root.querySelector('.ui-page.gameplay').style.opacity != '1' && target == 'title') {
1906     targetElems.push(game.ui.root.querySelector('.ui-page.gameplay'));
1907   }
1908   for(let targetElem of targetElems) {
1909     if(!targetElem.classList.contains('gameplay')) {
1910       targetElem.style.opacity = '0';
1911     }
1912     targetElem.style.display = 'flex';
1913     setTimeout((targetElem) => {
1914       targetElem.style.opacity = '1';
1915       if(target == 'credits') {
1916         targetElem.querySelector('.area').scrollTop = 0;
1917       }
1918     }, fadeDuration, targetElem);
1919   }
1920   if(target != 'pause' && game.ui.currentPage != 'pause') {
1921     game.timeProgress = 0;
1922   }
1923   if(target == 'pause') {
1924     game.view.music.stop();
1925     game.view.windSound.stop();
1926   } else if(game.ui.currentPage == 'pause' && target == 'openingcutscene') {
1927     if(game.timeProgress >= 1.0) {
1928       game.view.windSound.offset = game.timeProgress - 1.0;
1929       game.view.windSound.setVolume(game.settings['audio']['sounds']);
1930       if(!game.view.muted) {
1931         game.view.windSound.play();
1932       }
1933     }
1934   } else if(game.ui.currentPage == 'pause' && target == 'gameplay') {
1935     game.view.music.offset = (game.timeProgress / (game.settings['difficulty']['speed'] / 100)) % game.assets['audio']['music-' + game.settings['audio']['theme']].duration;
1936     if(!game.view.muted) {
1937       game.view.music.play();
1938     }
1939   }
1940   game.ui.previousPage = game.ui.currentPage;
1941   game.ui.currentPage = target;
1942   if(game.view) {
1943     game.startTime = game.view.clock.getElapsedTime();
1944   }
1947 game['fn'].unlockWithKey = (input) => {
1948   input = 'aBYPmb2xCwF2ilfD'+ input + 'PNHFwI2zKZejUv6c';
1949   let hash = (input) => {
1950     // Adapted with appreciation from bryc:
1951     // https://github.com/bryc/code/blob/master/jshash/experimental/cyrb53.js
1952     let h1 = 0xdeadbeef, h2 = 0x41c6ce57;
1953     for(let i = 0, ch; i < input.length; i++) {
1954       ch = input.charCodeAt(i);
1955       h1 = Math.imul(h1 ^ ch, 2654435761);
1956       h2 = Math.imul(h2 ^ ch, 1597334677);
1957     }
1958     h1  = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
1959     h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
1960     h2  = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
1961     h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
1962     return (h2 >>> 0).toString(16).padStart(8, 0) + (h1 >>> 0).toString(16).padStart(8, 0);
1963   }
1964   for(let unlockable of game.unlockables) {
1965     if(unlockable.accessKey == hash(input)) {
1966       let key = hash('UZx2jWen9w5jm0FB' + input + '7DZpEq4OOwv2kiJ1');
1967       let seed = parseInt(key.slice(12), 16);
1968       let prng = () => {
1969         seed |= 0;
1970         seed = seed + 0x9e3779b9 | 0;
1971         let t = seed ^ seed >>> 16;
1972         t = Math.imul(t, 0x21f0aaad);
1973         t = t ^ t >>> 15;
1974         t = Math.imul(t, 0x735a2d97);
1975         return ((t = t ^ t >>> 15) >>> 0);
1976       };
1977       let data = Uint8Array.from(atob(unlockable['payload']), (c) => c.codePointAt(0));
1978       let pad;
1979       for(let i = 0; i < data.length; i++) {
1980         if(i % 4 == 0) {
1981           pad = prng();
1982           pad = [pad % 256, (pad >> 8) % 256, (pad >> 16) % 256, (pad >> 24) % 256];
1983         }
1984         data[i] = data[i] ^ pad[i % 4];
1985       }
1986       data = new TextDecoder().decode(data);
1987       let result = JSON.parse(data);
1988       if(result['type'] == 'redirect') {
1989         return game['fn'].unlockWithKey(result['target']);
1990       } else {
1991         return result;
1992       }
1993     }
1994   }
1995   return null;
1996 };
1998 game['fn'].start = () => {
1999   game.ui = {
2000     root: document.querySelector('.upInTheAirGame .ui-container'),
2001     hud: document.querySelector('.upInTheAirGame .gameplay .hud'),
2002     gamepads: [],
2003   };
2004   game.settings = {};
2005   // If you're looking at the source code and the following seems scary, don't worry, it's just a few
2006   // unlockable feather textures. I liked easter eggs and cheat codes when I was young, and I didn't
2007   // want these to be trivially bypassable for people who can read the code.
2008   game.unlockables = [
2009     {
2010       'accessKey': '5b32eb7ad08488f4',
2011       'payload': 'k4JPu3sWfEhcgleieVGghixKSI10qdRRC5tAl39Tzy1U7Rx9EEEYbLx9wCcxAf7wC8r9mJZCOj8bNa7grMbUmTeCeWWPAg==',
2012     },
2013     {
2014       'accessKey': '6273da5894b2dd8b',
2015       'payload': 'XAFLhAjcTzsWgGb7DAMCKwHXjoyUg/yxkIUyLcV/7PpktgW3MHtXhh4OkVeANr52RfdbwfVpgO4dxuyYPaFZ4x4JDmI=',
2016     },
2017     {
2018       'accessKey': 'fb8b533451a6dd68',
2019       'payload': 'u2QtZwORGGkQsXRmPeJK2nUgxhFQSr7ewqLAC6l6lVXRShEVVpiqFZIf0y5MfnVptVHCxAuNZZF2sbc6LFxEBojTMI1R2tQfY7MEMYxs5Wi3/lsp53Xu3ASRd+N5aTemajx+56hiOtiLgqU5xhN9sq4qNgqj+y864VJJ/vFBYdtO7d5bhAU5TT1CK8K4uC+i8TDQL3BL4ykw8lQgRkImEsXnckBa9HORqt7/Tbp7KLiw2fGOBYDvdDTz2VmfiDaW7out8PSmUdBzti+DlWh/gTJ+LhU7pIhn943H08vGsXB3WjA0WAof/27BdhCCjGbVypBYv/f8lgAtBienoaT5Ckzth6AlUrFPwrxvb/5uagEfgzl8ziyMilhEe48Ef6gQQ8SqzFlH1RuxjtVcIdaP2gqgLCTkSSuw8tfVq6bu2wFoMoBtqcjT0qc6tUU9TRSGchOxq3l6tnLr7IvPbCTUdEMskWUfm1QRlWjxZKDEtPhiEz41QoAEXJM56Wd/b4N3Lg3IeFOP3DLrA2RqAd0MB6c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9Ojr7OouRg7rKlnJAzU/om73eb/numkzKzJQ7nLV5N3TSyUyw2FdfKn08Hekwbl1F+PGbyg/tSTx3xmyISBT9pGL9byrXpYMVHSVT+8oyeudhgF94wZSaYv2JhtQ+Ua6Om8T9Xi/o+TR11oR9gVVKTd0fzzKsrVMrIbu995Ao6NEXmIITEKloTj5SvMByufXHZwz7EloVfNQjxL8jq25ffMfIjCF336baIpiQpw4Cq43uQBtJNfbewT51zySeIhRQExJBGwdbBsORGgqZZxv8lJdEcP7SKXiRZay5YqKVeHnSXXyTEr5poF7sbieiiO9We2MH7pHNNJrMQtvWkMUHYRt6WXl00WBtDwuE6KZYAsTcscw/S+P4oiDs2zE42FilQZCwR+JY8bHpoW0AyMAEVzbpVtbOYUAt4/hW2Ye18Tun9nKyb0O8rhzE1iutQQC5FfUeqwrQ1x/jbHAoujJA9hUXAhmQEfaTb2Dyh1Ai4wfBWhDGRnlr8WXAdrPrLCoJiadE/DS6gDgId1xrF6wL5yKht46KapK48hmNkDftMn1uNMcq4N2l9g/Z3KOEo+xmwP9AYZgSoiLZsrh/CR6lVqL80poB2tz2pHh+cIGgK/KhtwxchA0D2ixOdqJMDJrWiKXBRTcX3CgpFR9vcMPItj/wb21jIeZuG1z+k+sAN5wrkgPmSRnqw=',
2020     },
2021     {
2022       'accessKey': '3c78e25c7b1106b6',
2023       'payload': 'dnbO28tXI2i2+o+etuRc0/Cfxd4UpdG1IRgqB0fTwJE1xCoK+TtB/JVGTquaD/stnIkKiA==',
2024     },
2025     {
2026       'accessKey': '5f79141f861a146a',
2027       'payload': 'IO59sEgiVtdv68PW1n+NdmYY6sGhOdG6BHA4BwVErVCIu25lohqBbDKgI+gWyCPVFUaFk76yW1Ji09i/n+swIQK5ayyfCeRoruxz2lA/Eoe0LTPqy2CPShxD0Pfi66AdgzQ+jMvHOi9Stw/t0XGGpLjrQfghJDnZpuEgipYG3PpiZbcbj3BVUuw7fV6idwGPBXoqagwXvscfjQppTq8LvuqgHYgSM6CXlK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mYuf8J+sMbOkLrZAlgYJaxQWHiiAghyshoN5Vw+6XJGxe3obLuvDBDReGxmiehzX97bH+5cmIP0S2bD06+K5Yqsay5Gnvmjtj4+R+MHYEdlXQu6wCelP34YIeBnFz//1p13vQg/gsugpGBIh0lOeolEmyekpBRIKtkaDiPf5Sem1zeqmtLtrPNU3iP+EbjE1Vp41CWkTe/zZI4syUHTEKTpJpTLT7htM38YCAZ7z7EYjLeBjWjKtew+yN5pDLl9MX0pE2PgWHCdCHcHHtQW43W1qI+XzGJmuKiNfyz6kWb7SeGaFVue5iayagFwNuFO5EWNS33dgHvlkxU3pLnorbht1l4IsqCIQJnTWTXdhmdUvMCcVecQ3ZZiIhpj6o+ZWkmpq2fmNRBIRPvvoEwn7KZ+8IWDGU+BhhEDC75wI0iIsVLH9u5i2KwV2swqC+3YM07HzLY9Yb2Sphdz/stTsuiBGrGeL1sxvbMcdG4Yenp9peYRnm6NfZ+zvx4N0P2gtG39+YSF9mHNfaKBhQdzMlVO/KrIR4oK3gq6lnsPFbEAFuITVyTqXWccYMoFhRctUF0hACqgE4aZWx2vnMwYEAogPVVmyEjRJ+hbdVybkhyOK8TTxKh1McUt8bGU22ykNZokuXxqiu2mOFfnOiEwVMTvt8P3uMDAJ0swpeGwSbRvEk5DZ1j0mY34G0gaEyMkzDSfsFGlFb+PDenq7Zz9zb6+8K6gI3DrB6piB1ZN1qsgTHi/SaOCyFCdDtaSHDCd0hWtdv9lu8ul78fNhAHV0THNagsSORQeOTmq9b3AzqB1r+PnsndH1S/qFlsBZddUihMuPttDTbsQ1z+UdzgeWs',
2028     },
2029     {
2030       'accessKey': 'c2cfaaebb10f00ab',
2031       'payload': 'CAVH/4AwEJzNt950XEAZP3Q92fMNasIje6K5FSBgjqchkxmrFxjlNHjadnrHWdqM+zrB',
2032     },
2033     {
2034       'accessKey': '130b037dadbe1d7a',
2035       'payload': 'jZptfK3lxBErac3b1JRNwehvv2VmeTfcHMA86jxoiwkcRmFa+0sqqtZ0a/iO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VPwRRBgGQ2es9DqaHswfHDtra1zkA+HxCHO47PUpSivwPmYQ95iukJ7GigZPb4IFvxfdJnc9xXoIMGYZIEJEb8+cViSGQsyTlNzJdtoYdJa/+Q1sOUAtysfGvTRaprgfWIX5ijhC54RQyd/CTcnp0FuHpS33SnDyGx1AU4U=',
2036     },
2037     {
2038       'accessKey': 'd8e8dd84f4b0c103',
2039       'payload': 'EGKsJYSjVVaxCBWPRUGjWuLMl3k7fB/7uKYp8wz28r/5XTaOJF7LnbPMpBwysAR8IR/whArG',
2040     },
2041     {
2042       'accessKey': 'd1f0242fccc5692d',
2043       'payload': 'XD7dTaReU3K9B21AlICDj8kDgKD2sBfd96oW1ewXAbcBfwPQZ+lRXiV7OxKP/M0U75m/9QF2g28WwQea+ELkbTz2QD4EVuvvQblcVEwbADup/DfTwl5MG1DpJu+Fd68NszJkNYpx6JoFkJbeOs4mzTaY7yL05AWnz8BTivokawBDlsu/ZSK79LNQxT2UoAcYDoDtLWBGg0WvtmUNHIZWgWkMVBcgqseSE9Y9R5XFoKU2HOizI1ZeUyCXNDDmp5d7DMTn5QYjkjho5nbav1TknN5TqGQ7N6DqcbN62Q4iBtSGqiyaL6HPUkZxZabcJhmyU4TQthpLNGve4FeDoyX1SimrLLeRyB9HtyG2LamIAogLVmZ6NEPwLtCus/xGmvdxwB6Kq7iY6b5jX9WTiW8DfTfh+2HzQL2LUUWbl31ZUljPRaFanetAk4hemPtuO7b6Azrwxs0Smy6/MNoBSEfwomDDYyQFiXsq8xPydU2lAImyQPtToywqIw7whbjdr2Uybf22E31uNIwaqOxnIDJu4vN71lKx3DSuvhOtQaP5x7L5LxlHN8uIJ/t22MorYBokl0p5ZXtGJBm4tXJHoaueLBRRncGAre577DfM4JIfu5kFd7yx8iMeL6u+0L+vQw+maUMWaxzy7a3TBK3Jq5AJKEVwRrwaS1LEjfGTgLYH3KczsdyrfEIEdSIcSMIUaAhNvnNKjFK+CaW2Iz34NfDyc8mIyQaChrF39kR3buGPsD6dL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ZTo41rNZiWO5Ok0R003kNkxsvumFRFw+VxYMJj+65MDbbJn77ar/DmcxIg7HaZnpZhFe2Uepsqo3IOsG/3lRyAttQ0UeeD0GIdvKn23eLbLDM23Wlh21pw1iL5Az5XzR7YKv0nQwzSi7vAazoPdxCXvCP9iRzHgSicqbdBfHBvsLFdAffc0WGtLFTs59UTVHKAu8eTW68zpfmUkHla2+zL4dAelwQrvY/BuBiZHRCl3Uzt4756e3GGWeaR9F7bxKg91fpwa+wxRx+4kkvpqgNYZB6Wvs7PFVixbzZhAb+nwf5J4jAEV6gxVbj3I5hug==',
2044     },
2045     {
2046       'accessKey': '452d9211d2fba161',
2047       'payload': 'grX6fMk05+btLNGB30W51iGiEMYKvRlymwDnDsWdM7FTESZ1InCZ9Cq+OA7TTmHKn48/tL7QuCpIX7plNb/wZaCN7PlKt8hSNVLhLOZtJeGTvp6w4f8tz7WchDPgDu7yH8dJRNMvPBAN7FXHqvt4S2M+TQIL3uXjBnPIuM+km6ujL8GU7VuZCZSIDdmIY3AQwkTyoUO8sir4SKoxUTYUfmw6bptHcXSIEFe4kV++Av7SlhtCTtGtdmRni4EMd8SwXnWlTON08+OnwTrEeG4MgHtp62uxe9MwT66ahI77pVJaNFEMZJSYkU4vbRelEzzIVGXH66afet0H7YzMIj9POlv5IVIiAo7Gz9RST2KqW4tSqjIhdLvrmMoXtCrjEvfF+qrRZporhgAjc7x4bB272Vjv3hTNefw7yLFaE0YuI9z2HbeSKuV8TkT+O7qxuBXZcUEfoFifSH17cVNNWkbptzFRPr2FwXgFJTUzgFCysLG7YGCrKiWcohjOD2Mt1SiPOigpMGJ85JjoNWZzSIFZSNqFj3HHvfojDv5Jxd3XO0BnbovBJI6FEZkm1droYPhIskw8DIOkHGbXmy6rkuuLi4NEaK93+aM5G4Ykmhll5OBQXl9IRtxWbxByQdH+6Hejpzvo6hEjGZI7C/pdVtfXAyBoXkiQeJXU7+TDN54EpyZSMsQvoWcQUd5i8t34DJ85ydEAup6XzQGHjYVi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.ui.root.querySelectorAll('.ui-page.credits .area h3').length > 3) {
2055     // If the credits have more than three third-level headers, that means we are
2056     // in the freeware version and can make the CSS adjustments it needs.
2057     let css = document.styleSheets[0];
2058     css.insertRule('.upInTheAirGame .ui-page.credits .person { position: relative; height: 4em; padding-left: calc(4em + 1ex); display: flex; flex-direction: column; justify-content: center; }');
2059     css.insertRule('.upInTheAirGame .ui-page.credits .person::before { content: " "; position: absolute; left: 0; box-sizing: border-box; width: 4em; height: 4em; background-size: contain; border-radius: .6em; border: .1em solid #d53c59; }');
2060     game.ui.root.querySelectorAll('.ui-page.credits .area .person').forEach((person) => {
2061       let personName = Array.from(person.classList).filter(c => c != 'person')[0];
2062       let imageFormat = (personName == 'nina') ? 'png' : 'jpg';
2063       css.insertRule('.upInTheAirGame .ui-page.credits .person.' + personName + '::before { background-image: url("' + game['deploymentOptions']['assetUrlPrefix'] + 'textures/person-' + personName + '.' + imageFormat + '"); }');
2064     });
2065   }
2067   game.ui.root.querySelectorAll('button.goto').forEach((btn) => {
2068     btn.addEventListener('click', (e) => {
2069       if(game.view && !game.view.music) {
2070         game.view.music = new THREE.Audio(game.view.audioListener);
2071         game.view.music.setBuffer(game.assets['audio']['music-' + game.settings['audio']['theme']]);
2072         game.view.music.setVolume(game.settings['audio']['music']);
2073         game.view.windSound = new THREE.Audio(game.view.audioListener);
2074         game.view.windSound.setBuffer(game.assets['audio']['wind']);
2075         game.view.windSound.setVolume(game.settings['audio']['sounds']);
2076         game.view.windSound.setLoop(false);
2077       }
2078       let btn = e.target.closest('button');
2079       let target = Array.from(btn.classList).filter(c => c != 'goto')[0];
2080       if(target == 'previous') {
2081         target = game.ui.previousPage;
2082       }
2083       game['fn'].moveToPage(target);
2084     });
2085   });
2087   game.ui.root.querySelectorAll('.options .controls input, .options .graphics input, .options .hud input, .options .feather input, .options .accessibility input, .options .accessibility select').forEach((elem) => {
2088     elem.addEventListener('change', () => {
2089       game['fn'].applySettings();
2090       if(elem.name == 'upInTheAirGame-controls') {
2091         game.ui.root.querySelector('.controls .leftside').style.display = (['touchpad', 'thumbstick'].includes(game.settings['controls'])) ? 'block' : 'none';
2092         game.ui.root.querySelectorAll('.options .controls p span:not(.' + game.settings['controls'] + ')').forEach(span => span.style.display = 'none');
2093         game.ui.root.querySelector('.options .controls span.' + game.settings['controls']).style.display = 'block';
2094       } else if(elem.value == 'highcontrast' || elem.name == 'upInTheAirGame-graphics') {
2095         game['fn'].createMeshes();
2096       } else if(elem.name == 'upInTheAirGame-feather') {
2097         game['fn'].createFeather();
2098       }
2099     });
2100   });
2102   game.ui.root.querySelector('.ui-page.title .system-buttons input').addEventListener('change', (e) => {
2103     game.view.muted = e.target.checked;
2104   });
2106   game.ui.root.querySelector('.ui-page.title .system-buttons button').addEventListener('click', (e) => {
2107     if(document.fullscreenElement == game.ui.root.parentNode) {
2108       document.exitFullscreen();
2109     } else {
2110       game.ui.root.parentNode.requestFullscreen();
2111     }
2112   });
2114   game.ui.root.querySelectorAll('.ui-page .audio input[type=range]').forEach((elem) => {
2115     elem.addEventListener('input', (e) => {
2116       let audioCategory = Array.from(e.target.classList).filter(v => ['music', 'sounds'].includes(v))[0];
2117       game.ui.root.querySelector('.ui-page.options .audio input[type=range].' + audioCategory).value = e.target.value;
2118       game['fn'].applySettings();
2119     });
2120   });
2122   game.ui.root.querySelectorAll('.options .audio button').forEach((btn) => {
2123     btn.addEventListener('click', (e) => {
2124       if(e.target.classList.contains('music')) {
2125         if(game.view.music.isPlaying) {
2126           game.view.music.stop();
2127           if(game.view.music.timeoutID) {
2128             clearTimeout(game.view.music.timeoutID);
2129             delete game.view.music.timeoutID;
2130           }
2131         } else {
2132           game.view.music.offset = 36;
2133           if(!game.view.muted) {
2134             game.view.music.play();
2135           }
2136           game.view.music.timeoutID = setTimeout(() => {
2137             game.view.music.stop();
2138           }, 6000);
2139         }
2140       } else if(e.target.classList.contains('sounds')) {
2141         game['fn'].playRandomSound();
2142       }
2143     });
2144   });
2146   game.ui.root.querySelectorAll('.options .keyboard label button').forEach((btn) => {
2147     btn.addEventListener('click', () => {
2148       if(game.ui.root.querySelector('.ui-page.keyboard-modal')) {
2149         return;
2150       }
2151       const keyboardModal = document.createElement('div');
2152       keyboardModal.classList.add('ui-page', 'keyboard-modal');
2153       const instruction = document.createElement('span');
2154       const direction = btn.classList[0];
2155       keyboardModal.classList.add(direction);
2156       instruction.innerText = 'Please press the key for “' + direction[0].toUpperCase() + direction.slice(1) + '”';
2157       keyboardModal.appendChild(instruction);
2158       game.ui.root.appendChild(keyboardModal);
2159     });
2160   });
2162   game.ui.root.querySelector('.options .keyboard button[value="reset"]').addEventListener('click', (e) => {
2163     const container = e.target.parentNode;
2164     container.querySelector('button.up').value = 'ArrowUp|w';
2165     container.querySelector('button.right').value = 'ArrowRight|d';
2166     container.querySelector('button.down').value = 'ArrowDown|s';
2167     container.querySelector('button.left').value = 'ArrowLeft|a';
2168     game['fn'].applySettings();
2169     game['fn'].loadSettings();
2170   });
2172   game.ui.root.querySelectorAll('.ui-page .areatabs button').forEach((btn) => {
2173     btn.addEventListener('click', (e) => {
2174       btn.parentNode.querySelectorAll('button').forEach((otherBtn) => {
2175         otherBtn.classList.remove('active');
2176         let val = otherBtn.classList[0];
2177         otherBtn.closest('.ui-page').querySelector('div.' + val).style.display = 'none';
2178       });
2179       btn.classList.add('active');
2180       let val = Array.from(btn.classList).filter(c => c != 'active')[0];
2181       btn.closest('.ui-page').querySelector('div.' + val).style.display = 'flex';
2182     });
2183   });
2185   game.ui.root.style.fontSize = (game.ui.root.clientWidth / 48) + 'px';
2186   window.addEventListener('resize', () => {
2187     game.ui.root.style.fontSize = (game.ui.root.clientWidth / 48) + 'px';
2188   });
2190   window.addEventListener('scroll', () => {
2191     if(!['gameplay', 'openingcutscene', 'endingcutscene'].includes(game.ui.currentPage)) {
2192       return;
2193     }
2194     let bbox = game.ui.root.querySelector('canvas').getBoundingClientRect();
2195     if(bbox.bottom < -100 || bbox.top - bbox.height > 100 || bbox.left + bbox.width < -100 || bbox.left - window.innerWidth > 100) {
2196       game['fn'].moveToPage('pause', true);
2197     }
2198   });
2199   window.addEventListener('blur', () => {
2200     if(['gameplay', 'openingcutscene', 'endingcutscene'].includes(game.ui.currentPage)) {
2201       game['fn'].moveToPage('pause', true);
2202     }
2203   });
2205   document.addEventListener('keydown', (e) => {
2206     const keyboardModal = game.ui.root.querySelector('.keyboard-modal');
2207     if(keyboardModal) {
2208       const direction = [...keyboardModal.classList].filter(c => c != 'ui-page' && c != 'keyboard-modal')[0];
2209       if(e.key != 'Escape') {
2210         game.ui.root.querySelector('.options .keyboard label button.' + direction).value = e.key;
2211         game['fn'].applySettings();
2212         game['fn'].loadSettings();
2213       }
2214       keyboardModal.remove();
2215       e.preventDefault();
2216       e.stopPropagation();
2217       return;
2218     }
2219     if(game.ui.currentPage == 'title' && e.key.match(/[a-z]/)) {
2220       game.view.cheatBuffer = (game.view.cheatBuffer + e.key).slice(-25);
2221       for(let len = 10; len <= 25; len++) {
2222         if(game.view.cheatBuffer.length < len) {
2223           break;
2224         }
2225         let unlock = game['fn'].unlockWithKey(game.view.cheatBuffer.slice(-len));
2226         if(unlock && unlock['type'] == 'feather' && !game.settings['unlocks'].includes(unlock['name'])) {
2227           game['fn'].playRandomSound();
2228           game['fn'].unlockFeather(unlock['name'], unlock['url']);
2229           game['fn'].moveToPage('unlock');
2230         } else if(unlock && unlock['type'] == 'custom') {
2231           if(!game.var.sessionUnlocks) {
2232             game.var.sessionUnlocks = [];
2233           }
2234           if(!game.var.sessionUnlocks.includes(unlock['name'])) {
2235             game['fn'].playRandomSound();
2236             let action = new Function(unlock['action']);
2237             action.call(null, game, THREE);
2238             game.var.sessionUnlocks.push(unlock['name']);
2239           }
2240         }
2241       }
2242       return;
2243     }
2244     if(e.key == 'Escape') {
2245       if(['gameplay', 'openingcutscene', 'endingcutscene'].includes(game.ui.currentPage)) {
2246         game['fn'].moveToPage('pause', true);
2247       } else if(game.ui.currentPage == 'pause') {
2248         game['fn'].moveToPage(game.ui.previousPage, true);
2249       }
2250     }
2251   });
2253   window.addEventListener('gamepadconnected', (e) => {
2254     game.ui.gamepads.push(e.gamepad);
2255   });
2256   window.addEventListener('gamepaddisconnected', (e) => {
2257     if(game.ui.gamepads.includes(e.gamepad)) {
2258       game.ui.gamepads.splice(game.ui.gamepads.indexOf(e.gamepad), 1);
2259     }
2260   });
2262   game.ui.root.querySelector('.ui-page.pause button.title').addEventListener('click', () => {
2263     game['fn'].reset();
2264   });
2266   game['fn'].loadAllAssets((progress) => {
2267     let percentage = Math.floor(100 * progress);
2268     game.ui.root.querySelector('.ui-page.loading progress').value = percentage;
2269     game.ui.root.querySelector('.ui-page.loading span').innerText = percentage;
2270   }).then(() => {
2271     if(window.location.hostname == 'fietkau.media' && window.location.pathname == '/up_in_the_air') {
2272       game.ui.root.querySelector('.ui-page.title .footer span:last-child').remove();
2273     }
2274     let controlsInterstitial = false;
2275     if(!game.settings['controls']) {
2276       controlsInterstitial = true;
2277       let control;
2278       if(matchMedia('(hover: hover)').matches) {
2279         control = 'mouse';
2280       } else {
2281         control = 'touchpad';
2282       }
2283       game.ui.root.querySelector('.controls input[value="' + control + '"]').checked = true;
2284       game['fn'].applySettings();
2285       game['fn'].loadSettings();
2286       game.ui.root.querySelectorAll('.ui-page.controls .' + ((control == 'mouse') ? 'touchpad' : 'mouse')).forEach(elem => elem.remove());
2287     }
2288     if(!game.assets.audiothemes.includes(game.settings['audio']['theme'])) {
2289       game.settings['audio']['theme'] = game.assets.audiothemes[0];
2290     }
2291     if(game.assets.audiothemes.length == 1) {
2292       game.ui.root.querySelector('.ui-page.options .audiotheme').style.display = 'none';
2293     }
2294     let container = game.ui.root.querySelector('.ui-page.options .audiotheme');
2295     for(let audioTheme of game.assets.audiothemes) {
2296       let snippet = container.children[0].content.cloneNode(true).children[0];
2297       snippet.children[0].value = audioTheme;
2298       if(audioTheme == game.settings['audio']['theme']) {
2299         snippet.children[0].checked = true;
2300       }
2301       snippet.children[0].addEventListener('change', () => {
2302         game['fn'].applySettings();
2303         game.view.music.setBuffer(game.assets['audio']['music-' + game.settings['audio']['theme']]);
2304       });
2305       snippet.childNodes[1].textContent = ' ' + audioTheme[0].toUpperCase() + audioTheme.slice(1);
2306       container.appendChild(snippet);
2307     }
2308     if(controlsInterstitial) {
2309       game['fn'].moveToPage('controls');
2310     } else {
2311       game['fn'].moveToPage('title');
2312     }
2313   }, (err) => {
2314     console.error(err);
2315   });
2317 };
2319 // Set up name mirrors for each function that should survive most minifiers and transpilers
2320 game['fn'].animate['friendlyName'] = 'animate';
2321 game['fn'].applyForceToFeather['friendlyName'] = 'applyForceToFeather';
2322 game['fn'].applySettings['friendlyName'] = 'applySettings';
2323 game['fn'].createFeather['friendlyName'] = 'createFeather';
2324 game['fn'].createMeshes['friendlyName'] = 'createMeshes';
2325 game['fn'].easeInOut['friendlyName'] = 'easeInOut';
2326 game['fn'].initializeGame['friendlyName'] = 'initializeGame';
2327 game['fn'].lerp['friendlyName'] = 'lerp';
2328 game['fn'].loadAllAssets['friendlyName'] = 'loadAllAssets';
2329 game['fn'].loadSettings['friendlyName'] = 'loadSettings';
2330 game['fn'].moveToPage['friendlyName'] = 'moveToPage';
2331 game['fn'].playRandomSound['friendlyName'] = 'playRandomSound';
2332 game['fn'].prepareWordMesh['friendlyName'] = 'prepareWordMesh';
2333 game['fn'].reset['friendlyName'] = 'reset';
2334 game['fn'].start['friendlyName'] = 'start';
2335 game['fn'].unlockFeather['friendlyName'] = 'unlockFeather';
2336 game['fn'].unlockWithKey['friendlyName'] = 'unlockWithKey';
2338 game['fn'].start();