2 // SPDX-License-Identifier: GPL-3.0-or-later
5 * – a browser game created for FediJam 2024 –
6 * https://fietkau.media/up_in_the_air
8 * Copyright (c) Julian Fietkau
9 * See README.txt for details.
11 *******************************************************************************
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.
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.
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/>.
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'] = {};
38 const deploymentDefaults = {
41 for(let k in deploymentDefaults) {
42 if(!game['deploymentOptions'].hasOwnProperty(k)) {
43 game['deploymentOptions'][k] = deploymentDefaults[k];
49 game['fn'].playRandomSound = () => {
50 if(!game.view || !game.view.audioListener) {
53 if(!game.view.lastSoundsCache) {
54 game.view.lastSoundsCache = [];
57 // We remember the last two notes played and make sure not to repeat one of those.
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);
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) {
73 game['fn'].easeInOut = (val) => {
74 return -0.5 * Math.cos(val * Math.PI) + 0.5;
77 game['fn'].lerp = (start, end, progress) => {
78 return (1.0 - progress) * start + progress * end;
81 game['fn'].loadAllAssets = (renderProgressCallback) => {
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'],
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.',
136 return new Promise((resolve, reject) => {
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,
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;
180 let unlock = game['fn'].unlockWithKey('NIbp2kW5' + unlockable + 'e2ZDFl5Y');
181 if(unlock && unlock['type'] == 'feather') {
182 todoList['data:textures/feather-' + unlock['name']] = unlock['url'];
186 game.assets.audiothemes = [];
187 const audioThemes = {
188 'classical': [1636930, 34002, 34629, 25399, 16426, 26122],
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);
199 let total = Object.keys(todoList).filter(k => !k.startsWith('data:')).map(k => todoList[k]).reduce((a, b) => a + b, 0);
202 'audio': new THREE.AudioLoader(),
203 'fonts': new FontLoader(),
204 'textures': new THREE.TextureLoader(),
206 for(let todo in todoList) {
207 let isDataUri = todo.startsWith('data:');
209 todo = todo.slice(5);
213 let segments = todo.split('/');
214 if(!(segments[0] in game.assets)) {
215 game.assets[segments[0]] = {};
217 if(!(segments[0] in loader)) {
218 reject('Unsupported resource: ' + todo);
222 url = todoList['data:' + todo];
224 url = game['deploymentOptions']['assetUrlPrefix'] + url;
226 loader[segments[0]].load(url, (result) => {
227 if(segments[0] == 'textures') {
228 result.colorSpace = THREE.SRGBColorSpace;
229 result.minFilter = THREE.NearestFilter;
230 result.magFilter = THREE.NearestFilter;
231 if(segments[1].split('.')[0].startsWith('feather-')) {
232 result.repeat = new THREE.Vector2(1, -1);
233 result.wrapT = THREE.RepeatWrapping;
234 } else if(segments[1].split('.')[0] == 'highcontrast-backdrop') {
235 result.repeat = new THREE.Vector2(25, 25);
236 result.wrapS = THREE.RepeatWrapping;
237 result.wrapT = THREE.RepeatWrapping;
240 game.assets[segments[0]][segments[1].split('.')[0]] = result;
241 if(todo in progress) {
242 progress[todo] = todoList[todo];
243 if(renderProgressCallback) {
244 renderProgressCallback(Object.keys(progress).map(k => progress[k]).reduce((a, b) => a + b, 0) / total);
248 if(todo in progress) {
249 progress[todo] = xhr.loaded;
250 if(renderProgressCallback) {
251 renderProgressCallback(Object.keys(progress).map(k => progress[k]).reduce((a, b) => a + b, 0) / total);
255 reject('Error while loading ' + todo + ': ' + err);
258 const loadingHeartbeat = () => {
259 let totalProgress = Object.keys(progress).map(k => progress[k]).reduce((a, b) => a + b, 0);
260 if(totalProgress == total) {
261 resolve(totalProgress);
263 setTimeout(loadingHeartbeat, 100);
266 setTimeout(loadingHeartbeat, 100);
270 game['fn'].applyForceToFeather = (vector) => {
271 game.objects.feather.speed.add(vector);
274 game['fn'].initializeGame = (canvas) => {
275 game.timeProgress = 0;
276 game.timeTotal = 258;
277 game.courseRadius = 50;
281 game.view.muted = false;
282 game.view.canvas = canvas;
283 game.ui.virtualInput = canvas.closest('.upInTheAirGame').querySelector('.virtual-input-widget');
285 const scene = new THREE.Scene();
286 game.view.camera = new THREE.PerspectiveCamera(75, canvas.width / canvas.height, 0.1, 1000);
287 game.view.camera.position.z = 5;
288 game.view.ambientLight = new THREE.AmbientLight(0xffffff, 2);
289 scene.add(game.view.ambientLight);
290 game.view.directionalLight1 = new THREE.DirectionalLight(0xffffff, 1);
291 game.view.directionalLight1.position.set(1, 1, 1);
292 scene.add(game.view.directionalLight1);
293 game.view.directionalLight2 = new THREE.DirectionalLight(0xffffff, 1);
294 game.view.directionalLight2.position.set(-1, -1, 1);
295 scene.add(game.view.directionalLight2);
296 game.view.directionalLight3 = new THREE.DirectionalLight(0xffffff, 1);
297 game.view.directionalLight3.position.set(0, -1, 1);
298 scene.add(game.view.directionalLight3);
299 game.view.renderer = new THREE.WebGLRenderer({ canvas: canvas, antialias: false });
300 game.view.renderer.setSize(canvas.width, canvas.height);
301 game.view.renderer.setClearColor(0x808080, 1);
302 let resolution = Math.round(3200 / Math.pow(2, game.settings['graphics']));
303 game.view.canvas.width = resolution;
304 game.view.canvas.height = resolution;
305 game.view.camera.updateProjectionMatrix();
306 game.view.renderer.setSize(game.view.canvas.width, game.view.canvas.height);
307 game.view.clock = new THREE.Clock();
308 game.view.clock.previousTime = 0;
309 game.view.clock.getDeltaTime = () => {
310 const elapsedTime = game.view.clock.getElapsedTime();
311 const deltaTime = elapsedTime - game.view.clock.previousTime;
312 game.view.clock.previousTime = elapsedTime;
316 const pinwheelGeometry = new THREE.BoxGeometry(.9, .9, 0.01);
317 const pinwheelMaterial = new THREE.MeshPhongMaterial({
318 map: game.assets.textures.pinwheel,
323 game.objects.pinwheel = new THREE.Mesh(pinwheelGeometry, [null, null, null, null, pinwheelMaterial, null]);
324 game.objects.pinwheel.position.setY(2);
325 game.objects.pinwheel.position.setZ(-1);
326 game.objects.pinwheel.opacity = 0;
327 scene.add(game.objects.pinwheel);
329 for(let time of ['day', 'evening']) {
330 game.objects[time + 'House'] = new THREE.Group();
331 for(let layer of [1, 2, 3]) {
332 let material = new THREE.MeshBasicMaterial({
333 map: game.assets['textures']['house-' + time + '-' + layer],
339 dimensions = [14, 14, 0, 0, -2];
340 } else if(layer == 2) {
341 dimensions = [6, 3.4455, -1.4, -3.6, -3];
342 } else if(layer == 3) {
343 dimensions = [10, 10, -4, -2, -6];
345 let mesh = new THREE.Mesh(new THREE.PlaneGeometry(dimensions[0], dimensions[1]), material);
346 mesh.position.set(dimensions[2], dimensions[3], dimensions[4]);
347 if(time == 'evening') {
348 mesh.position.setX(-mesh.position.x);
350 game.objects[time + 'House'].add(mesh);
352 game.objects[time + 'House'].position.set(-11.5, -game.courseRadius - 4, -7);
353 if(time == 'evening') {
354 game.objects[time + 'House'].position.x *= -1;
358 game.view.camera.position.set(-5, -game.courseRadius, game.view.camera.position.z);
359 game.view.scene = scene;
361 game['fn'].createMeshes();
362 game['fn'].createFeather();
365 function pinwheelPositionUpdate(game, viewportX, viewportY) {
366 const vFOV = THREE.MathUtils.degToRad(game.view.camera.fov);
367 const viewportHeight = 2 * Math.tan(vFOV / 2) * (game.view.camera.position.z - game.objects.pinwheel.position.z);
368 game.controls.positionX = viewportHeight * viewportX;
369 game.controls.positionY = - viewportHeight * viewportY;
372 function cursorMoveEvent(game, target, viewportLocalX, viewportLocalY, pressed) {
373 if(game.settings['controls'] == 'mouse' || game.settings['controls'] == 'touchpad') {
374 let sensorElem = game.view.canvas;
375 if(game.settings['controls'] == 'touchpad') {
376 sensorElem = game.ui.virtualInput;
378 let bbox = sensorElem.getBoundingClientRect();
379 // Intentional division by height instead of width in the following line, since
380 // three.js controls the vertical FOV. So if we ever change the aspect ratio from 1:1,
381 // y will still be in range (-0.5, 0.5), but the range for x will be smaller or larger.
382 let x = (viewportLocalX - bbox.x - (bbox.width / 2)) / bbox.height;
383 let y = (viewportLocalY - bbox.y - (bbox.height / 2)) / bbox.height;
384 if(game.settings['controls'] == 'touchpad') {
385 sensorElem.children[0].style.left = ((0.5 + x) * 100) + '%';
386 sensorElem.children[0].style.top = ((0.5 + y) * 100) + '%';
388 if(game.settings['controls'] == 'touchpad') {
392 // The pinwheel gets to go a little bit past the edge of the playing field.
393 const maxDist = 0.55;
394 if(game.settings['controls'] == 'mouse' || (pressed && Math.abs(x) <= maxDist && Math.abs(y) <= maxDist)) {
395 pinwheelPositionUpdate(game, x, y);
398 if(game.settings['controls'] == 'thumbstick') {
399 if(!game.ui.virtualInput.inProgress) {
402 let bbox = game.ui.virtualInput.getBoundingClientRect();
405 x = (viewportLocalX - bbox.x - (bbox.width / 2)) / bbox.height;
406 y = (viewportLocalY - bbox.y - (bbox.height / 2)) / bbox.height;
407 let vLen = Math.sqrt(4 * x * x + 4 * y * y);
408 x = x / Math.max(vLen, 0.6);
409 y = y / Math.max(vLen, 0.6);
414 let speedScale = 7.0;
417 if(Math.abs(speedX) < deadZone) {
421 if(Math.abs(speedY) < deadZone) {
424 game.controls.speedX = speedScale * speedX;
425 game.controls.speedY = -1 * speedScale * speedY;
428 game.ui.virtualInput.children[0].style.left = ((0.5 + x) * 100) + '%';
429 game.ui.virtualInput.children[0].style.top = ((0.5 + y) * 100) + '%';
433 function keyboardEvent(game, key, motion) {
434 if(game.settings['controls'] != 'keyboard') {
437 if(motion == 'down') {
438 if(game.controls.heldKeys.includes(key)) {
441 game.controls.heldKeys.push(key);
443 if(game.controls.heldKeys.includes(key)) {
444 game.controls.heldKeys.splice(game.controls.heldKeys.indexOf(key), 1);
447 if(game.settings['keyboard']['tapmode']) {
448 if(motion != 'down') {
451 if(game.settings['keyboard']['up'].includes(key)) {
452 game.controls.speedY = Math.max(0.0, game.controls.speedY + 2.0);
454 if(game.settings['keyboard']['down'].includes(key)) {
455 game.controls.speedY = Math.min(0.0, game.controls.speedY - 2.0);
457 if(game.settings['keyboard']['right'].includes(key)) {
458 game.controls.speedX = Math.max(0.0, game.controls.speedX + 2.0);
460 if(game.settings['keyboard']['left'].includes(key)) {
461 game.controls.speedX = Math.min(0.0, game.controls.speedX - 2.0);
465 if(motion == 'down' && game.settings['keyboard']['up'].includes(key)) {
466 game.controls.accelY = 15.0;
467 game.controls.speedY = 0.0;
469 if(motion == 'down' && game.settings['keyboard']['down'].includes(key)) {
470 game.controls.accelY = -15.0;
471 game.controls.speedY = 0.0;
473 if(motion == 'down' && game.settings['keyboard']['right'].includes(key)) {
474 game.controls.accelX = 15.0;
475 game.controls.speedX = 0.0;
477 if(motion == 'down' && game.settings['keyboard']['left'].includes(key)) {
478 game.controls.accelX = -15.0;
479 game.controls.speedX = 0.0;
481 if(motion == 'up' && game.settings['keyboard']['up'].includes(key)) {
482 game.controls.accelY = Math.min(0.0, game.controls.accelY);
483 game.controls.speedY = Math.min(0.0, game.controls.speedY);
485 if(motion == 'up' && game.settings['keyboard']['down'].includes(key)) {
486 game.controls.accelY = Math.max(0.0, game.controls.accelY);
487 game.controls.speedY = Math.max(0.0, game.controls.speedY);
489 if(motion == 'up' && game.settings['keyboard']['right'].includes(key)) {
490 game.controls.accelX = Math.min(0.0, game.controls.accelX);
491 game.controls.speedX = Math.min(0.0, game.controls.speedX);
493 if(motion == 'up' && game.settings['keyboard']['left'].includes(key)) {
494 game.controls.accelX = Math.max(0.0, game.controls.accelX);
495 game.controls.speedX = Math.max(0.0, game.controls.speedX);
499 document.body.addEventListener('mousemove', e => cursorMoveEvent(game, e.target, e.clientX, e.clientY, (e.buttons % 2 == 1)));
500 document.body.addEventListener('mousedown', e => {
501 if(game.settings['controls'] == 'touchpad' || game.settings['controls'] == 'thumbstick') {
502 if(e.target.closest('.virtual-input-widget') == game.ui.virtualInput) {
503 game.ui.virtualInput.inProgress = true;
504 game.ui.virtualInput.children[0].style.display = 'block';
507 game.ui.virtualInput.inProgress = false;
508 if(game.settings['controls'] == 'touchpad') {
509 game.ui.virtualInput.children[0].style.display = 'none';
513 cursorMoveEvent(game, e.target, e.clientX, e.clientY, (e.buttons % 2 == 1));
515 document.body.addEventListener('mouseup', e => {
516 cursorMoveEvent(game, e.target, e.clientX, e.clientY, (e.buttons % 2 == 1));
517 if(game.settings['controls'] == 'touchpad' || game.settings['controls'] == 'thumbstick') {
518 game.ui.virtualInput.inProgress = false;
519 if(game.settings['controls'] == 'touchpad') {
520 game.ui.virtualInput.children[0].style.display = 'none';
522 game.ui.virtualInput.children[0].style.transitionDuration = '50ms';
523 setTimeout(() => { game.ui.virtualInput.children[0].style.transitionDuration = '0ms'; }, 75);
525 cursorMoveEvent(game, e.target, 0, 0, false);
528 document.body.addEventListener('touchmove', e => cursorMoveEvent(game, e.target, e.touches[0].clientX, e.touches[0].clientY, true));
529 document.body.addEventListener('touchstart', e => {
530 if(game.settings['controls'] == 'touchpad' || game.settings['controls'] == 'thumbstick') {
531 if(e.target.closest('.virtual-input-widget') == game.ui.virtualInput) {
532 game.ui.virtualInput.inProgress = true;
533 game.ui.virtualInput.children[0].style.display = 'block';
536 game.ui.virtualInput.inProgress = false;
537 if(game.settings['controls'] == 'touchpad') {
538 game.ui.virtualInput.children[0].style.display = 'none';
542 cursorMoveEvent(game, e.target, e.touches[0].clientX, e.touches[0].clientY, true);
544 document.body.addEventListener('touchend', e => {
545 if(e.target.closest('.ui-container') && game.settings['controls'] != 'mouse' && ['gameplay', 'openingcutscene', 'endingcutscene'].includes(game.ui.currentPage)) {
546 game['fn'].moveToPage('pause', true);
549 if(game.settings['controls'] == 'touchpad' || game.settings['controls'] == 'thumbstick') {
550 game.ui.virtualInput.inProgress = false;
551 if(game.settings['controls'] == 'touchpad') {
552 game.ui.virtualInput.children[0].style.display = 'none';
554 game.ui.virtualInput.children[0].style.transitionDuration = '50ms';
555 setTimeout(() => { game.ui.virtualInput.children[0].style.transitionDuration = '0ms'; }, 75);
557 cursorMoveEvent(game, e.target, 0, 0, false);
560 document.body.addEventListener('keydown', e => keyboardEvent(game, e.key, 'down'));
561 document.body.addEventListener('keyup', e => keyboardEvent(game, e.key, 'up'));
563 // All vectors used by the game loop (no allocations inside)
565 game.var.featherLocalPos = new THREE.Vector3();
566 game.var.featherBorderForce = new THREE.Vector3();
567 game.var.pinwheelDistance = new THREE.Vector3();
568 game.var.pinwheelRotationSpeed = 0;
569 game.var.notCollectedPos = new THREE.Vector3();
570 game.var.collectedPos = new THREE.Vector3();
571 game.var.endingEntryTrajectory = new THREE.Vector3();
572 game.var.endingExitTrajectory = new THREE.Vector3();
573 game.var.endingEntryRotation = new THREE.Vector3();
574 game.var.endingExitRotation = new THREE.Vector3();
575 game.view.renderer.setAnimationLoop(() => { game['fn'].animate(scene); });
578 game['fn'].prepareWordMesh = (word) => {
579 while(word.children.length > 0) {
580 word.remove(word.children[0]);
582 if(game.settings['graphics'] <= 2 && !game.settings['highcontrast']) {
583 for(let letter of word.text) {
584 let geometry = game.assets.fonts.geometry[letter];
585 let material = game.view.materials.letter;
586 if(geometry.customMaterial) {
587 material = geometry.customMaterial;
589 let mesh = new THREE.Mesh(geometry, material);
590 // We wrap each letter in a surrounding group in order to move the center point
591 // from the corner of the letter to its center. This makes rotations easier.
592 let container = new THREE.Group();
593 mesh.position.set(-game.assets.fonts.geometry[letter].dx, -game.assets.fonts.geometry[letter].dy, 0);
597 } else if(game.settings['graphics'] == 3 || game.settings['highcontrast']) {
598 let mesh = new THREE.Mesh(Object.values(game.assets.fonts.geometry)[0], game.view.materials.letter);
603 game['fn'].reset = () => {
605 game.controls.positionX = 0;
606 game.controls.positionY = 0;
607 game.controls.speedX = 0;
608 game.controls.speedY = 0;
609 game.controls.accelX = 0;
610 game.controls.accelY = 0;
611 game.controls.heldKeys = [];
612 game.ui.reachedEnd = false;
613 if(game.settings['graphics'] <= 2 && !game.settings['highcontrast']) {
614 for(let i = 0; i < 6; i++) {
615 game.view.materials['cloud' + i].uniforms.lerp.value = 0.0;
618 game.view.scene.add(game.objects.dayHouse);
619 game.view.scene.remove(game.objects.eveningHouse);
620 game.objects.feather.position.set(-11.45, -game.courseRadius - 4.2, -9.9);
621 game.objects.feather.rotation.set(Math.PI, 0, Math.PI / 2.1);
622 game.objects.pinwheel.material[4].opacity = 0.0;
624 game.ui.root.querySelector('.ui-page.title').classList.remove('end');
627 if(game.objects.words) {
628 for(let word of game.objects.words) {
629 game.view.scene.remove(word);
632 game.objects.words = [];
633 game.objects.words.collectedCount = 0;
634 game.ui.hud.children[1].innerText = '0';
635 const interWordDistance = new THREE.Vector3();
636 let placementSuccess;
638 for(let i = 0; i < 100; i++) {
640 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));
642 angleInCourse = Math.random();
643 } while(clusteringFunction(angleInCourse) < Math.random());
644 angleInCourse = (0.08 + 0.87 * angleInCourse);
646 angleInCourse = 0.05;
648 let randomCameraX = game.courseRadius * Math.sin(angleInCourse * 2 * Math.PI);
649 let randomCameraY = game.courseRadius * -Math.cos(angleInCourse * 2 * Math.PI);
650 let word = new THREE.Group();
651 if(wordList.length == 0) {
652 wordList.push(...game.assets.wordList);
654 let wordIndex = Math.floor(Math.random() * wordList.length);
655 word.text = wordList.splice(wordIndex, 1)[0];
656 game['fn'].prepareWordMesh(word);
657 word.randomAnimOffset = Math.random();
658 const vFOV = THREE.MathUtils.degToRad(game.view.camera.fov);
661 let randomPlacementRadius = Math.min(0.8, angleInCourse) * Math.tan(vFOV / 2) * Math.abs(word.position.z - game.view.camera.position.z);
663 randomPlacementRadius = 0;
665 let randomPlacementAngle = Math.random() * 2 * Math.PI;
666 let randomPlacementX = Math.sin(randomPlacementAngle) * randomPlacementRadius;
667 let randomPlacementY = Math.cos(randomPlacementAngle) * randomPlacementRadius;
668 word.position.set(randomCameraX + randomPlacementX, randomCameraY + randomPlacementY, 0);
669 placementSuccess = true;
670 for(let j = 0; j < i; j++) {
671 if(interWordDistance.subVectors(word.position, game.objects.words[j].position).length() <= 1.2) {
672 placementSuccess = false;
678 angleInCourse = 0.04 + 0.92 * Math.random();
681 } while(!placementSuccess);
682 game.view.scene.add(word);
683 game.objects.words.push(word);
687 game['fn'].animate = (scene) => {
688 if(!('startTime' in game)) {
689 game.startTime = game.view.clock.getElapsedTime();
691 if(game.ui.currentPage == 'pause') {
694 let delta = Math.min(game.view.clock.getDeltaTime(), 1 / 12);
695 if(game.ui.currentPage == 'gameplay') {
696 delta = delta * (game.settings['difficulty']['speed'] / 100);
698 game.timeProgress = (game.timeProgress + delta);
700 if(game.settings['controls'] == 'gamepad') {
701 let speedScale = 7.0;
705 for(let gamepad of game.ui.gamepads) {
706 let sx = gamepad.axes[0];
707 if(Math.abs(sx) < deadZone) {
711 let sy = gamepad.axes[1];
712 if(Math.abs(sy) < deadZone) {
717 if(speedX.length > 0) {
718 speedX = speedX.reduce((s, a) => s + a, 0) / speedX.length;
722 if(speedY.length > 0) {
723 speedY = speedY.reduce((s, a) => s + a, 0) / speedY.length;
727 game.controls.speedX = speedScale * speedX;
728 game.controls.speedY = -1 * speedScale * speedY;
731 const maxPinwheelSpeed = 8.0;
732 const maxPinwheelDistance = 5.0;
733 game.controls.speedX += delta * game.controls.accelX;
734 game.controls.speedY += delta * game.controls.accelY;
735 game.controls.speedX = Math.min(maxPinwheelSpeed, Math.max(-maxPinwheelSpeed, game.controls.speedX));
736 game.controls.speedY = Math.min(maxPinwheelSpeed, Math.max(-maxPinwheelSpeed, game.controls.speedY));
737 game.controls.positionX += delta * game.controls.speedX;
738 game.controls.positionY += delta * game.controls.speedY;
739 if(game.controls.positionX > maxPinwheelDistance) {
740 game.controls.positionX = maxPinwheelDistance;
741 game.controls.speedX = Math.max(0.0, game.controls.speedX);
742 game.controls.accelX = Math.max(0.0, game.controls.accelX);
743 } else if(game.controls.positionX < -maxPinwheelDistance) {
744 game.controls.positionX = -maxPinwheelDistance;
745 game.controls.speedX = Math.min(0.0, game.controls.speedX);
746 game.controls.accelX = Math.min(0.0, game.controls.accelX);
748 if(game.controls.positionY > maxPinwheelDistance) {
749 game.controls.positionY = maxPinwheelDistance;
750 game.controls.speedY = Math.max(0.0, game.controls.speedY);
751 game.controls.accelY = Math.max(0.0, game.controls.accelY);
752 } else if(game.controls.positionY < -maxPinwheelDistance) {
753 game.controls.positionY = -maxPinwheelDistance;
754 game.controls.speedY = Math.min(0.0, game.controls.speedY);
755 game.controls.accelY = Math.min(0.0, game.controls.accelY);
758 if(game.ui.currentPage != 'gameplay') {
759 let cameraSwayFactor = 1;
760 if(game.settings['graphics'] == 3) {
761 cameraSwayFactor = 0;
763 let cameraX, cameraY;
764 if(['options', 'credits', 'outro', 'unlock'].includes(game.ui.currentPage)) {
765 cameraX = game.ui.reachedEnd ? 5 : -5;
768 if(game.ui.currentPage == 'title') {
771 if(!game.ui.reachedEnd) {
772 game.objects.feather.position.set(cameraX - 8.45, -game.courseRadius - 6.4, -9.9);
773 game.objects.feather.rotation.set(Math.PI, 0, Math.PI / 2.1);
777 if(!game.ui.reachedStart) {
778 if(game.timeProgress < 1) {
779 game.ui.root.querySelector('.ui-page.title h1').style.opacity = '0';
780 game.ui.root.querySelectorAll('.ui-page.title > button').forEach((btn) => {
782 btn.style.position = 'relative';
783 btn.style.left = '10em';
784 btn.style.opacity = '0';
786 game.ui.root.querySelector('.ui-page.title .footer').style.opacity = '0';
787 game.ui.root.querySelector('.ui-page.title .system-buttons').style.opacity = '0';
788 cameraX += Math.max(0.0, 1 - game['fn'].easeInOut(0.5 + game.timeProgress / 2));
789 cameraY += Math.max(0.0, 10 * Math.pow(0.5 - game.timeProgress / 2, 2));
790 } else if(game.timeProgress >= 1.0 && game.timeProgress <= 2.1) {
791 game.ui.root.querySelector('.ui-page.title h1').style.opacity = Math.min(1.0, game.timeProgress - 1.0).toFixed(2);
793 if(game.timeProgress >= 1.5 && game.timeProgress <= 3.0) {
794 game.ui.root.querySelectorAll('.ui-page.title > button').forEach((btn) => {
795 let timeOffset = Array.from(btn.parentNode.children).indexOf(btn) - 2;
796 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';
797 let opacity = game['fn'].easeInOut(Math.max(0.0, Math.min(1.0, -0.3 * timeOffset + game.timeProgress - 1.5)));
798 btn.style.opacity = opacity.toFixed(2);
800 btn.disabled = false;
804 if(game.timeProgress >= 3.0 && game.timeProgress <= 4.0) {
805 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);
806 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);
808 if(game.timeProgress > 4.0 && !game.ui.reachedStart) {
809 game.ui.root.querySelector('.ui-page.title h1').removeAttribute('style');
810 game.ui.root.querySelectorAll('.ui-page.title > button').forEach(btn => { btn.disabled = false; btn.removeAttribute('style'); });
811 game.ui.root.querySelector('.ui-page.title .footer').removeAttribute('style');
812 game.ui.root.querySelector('.ui-page.title .system-buttons').removeAttribute('style');
813 game.ui.reachedStart = true;
816 } else if(game.ui.currentPage == 'openingcutscene') {
819 if(game.ui.reachedEnd) {
822 if(game.timeProgress < 0.1 && !game.view.windSound.isPlaying) {
823 game.view.windSound.stop();
824 game.objects.feather.position.set(cameraX - 8.45, -game.courseRadius - 6.4, -9.9);
825 game.objects.feather.rotation.set(Math.PI, 0, Math.PI / 2.1);
827 if(game.timeProgress > 1.0 && game.timeProgress <= 1.1 && !game.ui.root.querySelector('.gameplay p')) {
828 const lines = ['Why are the simplest words…', '…often the most difficult to write?'];
829 for(let line of lines) {
830 let elem = document.createElement('p');
831 elem.innerText = line;
832 elem.style.left = (1.5 + 2 * lines.indexOf(line)) + 'em';
833 elem.style.top = (1 + 1.2 * lines.indexOf(line)) + 'em';
834 elem.style.opacity = '0';
835 document.querySelector('.ui-page.gameplay').appendChild(elem);
837 if(!game.view.windSound.isPlaying) {
838 game.view.windSound.setVolume(game.settings['audio']['sounds']);
839 game.view.windSound.offset = 0;
840 if(!game.view.muted) {
841 game.view.windSound.play();
845 if(game.timeProgress > 1.0 && game.timeProgress <= 5.0) {
846 game.ui.root.querySelectorAll('.ui-page.gameplay p').forEach((elem) => {
847 let opacity = Math.max(0.0, Math.min(1.0, game.timeProgress - (elem.nextSibling ? 1.0 : 3.5)));
848 elem.style.transform = 'translateX(' + (Math.pow(1.0 - opacity, 2) * 10).toFixed(2) + 'em)';
849 elem.style.opacity = opacity.toFixed(2);
852 if(game.timeProgress >= 1.0 && game.timeProgress <= 3.0) {
853 let windStrength = 0.5 * (1 + Math.cos((game.timeProgress - 2.0) * Math.PI));
854 game.objects.feather.position.x = cameraX - 8.45 + 0.15 * windStrength;
855 game.objects.feather.rotation.z = Math.PI / 2.1 - 0.2 * windStrength;
857 if(game.timeProgress >= 3.0) {
858 let windStrength = Math.max(0.5 * (1 + Math.cos((game.timeProgress - 4.0) * Math.PI)), Math.min(2 * (game.timeProgress - 4.2), 1.2));
859 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)));
860 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));
861 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);
862 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)));
863 game.objects.feather.rotation.z = Math.PI / 2.1 - 0.2 * windStrength + 1.45 * Math.max(0.0, game.timeProgress - 5.0);
864 game.objects.feather.rotation.x = Math.PI + Math.max(0.0, game.timeProgress - 4.5) * Math.sin(Math.pow(game.timeProgress - 4.5, 2));
866 if(game.timeProgress > 7.0) {
867 game.ui.root.querySelectorAll('.ui-page.gameplay p').forEach((elem) => {
868 let opacity = Math.max(0.0, Math.min(1.0, 8.0 - game.timeProgress));
869 elem.style.opacity = opacity.toFixed(2);
872 cameraSwayFactor = cameraSwayFactor * (1 - (game.timeProgress / 8));
873 cameraX = -5 + Math.pow(Math.max(0, game.timeProgress - 3) / 5, 1.6) * 5;
875 if(game.timeProgress > 6.0 && game.timeProgress < 7.0 && game.settings['controls'] != 'mouse') {
876 game.controls.positionX = 0;
877 game.controls.positionY = -3;
879 game.objects.pinwheel.material[4].opacity = game['fn'].easeInOut(Math.max(0, (game.timeProgress - 7)));
880 if(game.timeProgress >= 8.0) {
881 game.ui.root.querySelectorAll('.ui-page.gameplay p').forEach((elem) => {
882 let opacity = Math.max(0.0, Math.min(1.0, 8.0 - game.timeProgress));
883 elem.style.opacity = opacity.toFixed(2);
885 game.view.music.offset = 0;
886 if(!game.view.muted) {
887 game.view.music.play();
889 game['fn'].moveToPage('gameplay', true);
891 } else if(game.ui.currentPage == 'endingcutscene') {
894 cameraSwayFactor = cameraSwayFactor * game.timeProgress / 8;
895 cameraX = 5 - Math.pow(Math.max(0, 5 - game.timeProgress) / 5, 1.6) * 5;
896 let trajectoryLerpValue = game['fn'].easeInOut(Math.min(6.0, game.timeProgress) / 6);
897 game.var.endingEntryTrajectory.addScaledVector(game.objects.feather.speed, delta);
898 game.var.endingExitTrajectory.setX(11.2 * game['fn'].easeInOut(Math.min(1, 1 - Math.max(0, 4 - game.timeProgress) / 4)));
899 game.var.endingExitTrajectory.setY(-game.courseRadius - 7.6 * game['fn'].easeInOut(Math.min(1, 1 - Math.max(0, 4 - game.timeProgress) / 4)));
900 game.var.endingExitTrajectory.setZ(-8.9 * game['fn'].easeInOut(Math.min(1, 1 - Math.max(0, 4 - game.timeProgress) / 4)));
901 game.objects.feather.rotation.x = game['fn'].lerp(game.var.endingEntryRotation.x, game.var.endingExitRotation.x, trajectoryLerpValue);
902 game.objects.feather.rotation.y = game['fn'].lerp(game.var.endingEntryRotation.y, game.var.endingExitRotation.y, trajectoryLerpValue);
903 game.objects.feather.rotation.z = game['fn'].lerp(game.var.endingEntryRotation.z, game.var.endingExitRotation.z, trajectoryLerpValue);
904 game.objects.feather.position.lerpVectors(game.var.endingEntryTrajectory, game.var.endingExitTrajectory, trajectoryLerpValue);
905 game.objects.pinwheel.material[4].opacity = game['fn'].easeInOut(Math.max(0, (1 - game.timeProgress)));
906 if(!game.settings['highcontrast']) {
907 let letterScale = game['fn'].lerp(0.3, 0.0, game['fn'].easeInOut(Math.max(0, Math.min(1, game.timeProgress - 6))));
908 for(let i = 0; i < game.objects.words.length; i++) {
909 let word = game.objects.words[i];
910 if(!word.collected) {
914 let collectionAnimationDuration = 1.0;
915 for(let j = 0; j < word.children.length; j++) {
916 let letter = word.children[j];
917 let animationProgress = (((game.timeProgress + 5 * word.randomAnimOffset) % 5) / 5 + j / 37) % 1;
918 x = game.objects.feather.scale.x * 0.5 * Math.cos(animationProgress * 1 * Math.PI * 2);
919 y = 0.2 * Math.sin(animationProgress * 7 * Math.PI * 2);
920 z = 0.2 * Math.cos(animationProgress * 7 * Math.PI * 2);
921 x = x * Math.cos(game.objects.feather.rotation.z) - y * Math.sin(game.objects.feather.rotation.z);
922 y = y * Math.cos(game.objects.feather.rotation.z) + x * Math.sin(game.objects.feather.rotation.z);
923 x += game.objects.feather.position.x - word.position.x;
924 y += game.objects.feather.position.y - word.position.y;
925 z += game.objects.feather.position.z - word.position.z;
926 if(i == 0 && !word.collected) {
927 // If we don't catch this edge case here, the manually placed first word might be visible
928 // in the closing cutscene if it is not collected.
931 letter.position.set(x, y, z);
932 let rotation = (game.timeProgress * 3 + 2 * Math.PI * word.randomAnimOffset) % (2 * Math.PI);
933 letter.rotation.set(rotation + j, rotation + 2*j, rotation + 3*j);
934 letter.scale.set(letterScale, letterScale, letterScale);
938 if(game.timeProgress >= 8) {
939 game.ui.root.querySelector('.ui-page.title').classList.add('end');
940 game['fn'].moveToPage('outro', true);
942 } else if(game.ui.reachedEnd) {
946 if(typeof(cameraX) == 'number' && typeof(cameraY) == 'number') {
947 game.view.camera.position.setY(cameraY - game.courseRadius + 0.07 * cameraSwayFactor * Math.sin(game.view.clock.getElapsedTime() * 0.5));
948 game.view.camera.position.setX(cameraX + 0.05 * cameraSwayFactor * Math.sin(game.view.clock.getElapsedTime() * 0.7));
950 game.view.renderer.render(scene, game.view.camera);
953 if(game.settings['enablehud']) {
954 if(game.timeProgress < 0.5) {
955 game.ui.hud.style.opacity = Math.min(1, game.timeProgress * 4).toFixed(2);
957 const failsafe = 0.0001;
958 const radiusOuter = 0.5;
959 const radiusInner = 0.4;
960 const progress = Math.max(failsafe, Math.min(1 - failsafe, game.timeProgress / game.timeTotal));
961 const xOuter = (0.5 + radiusOuter * Math.sin(progress * 2 * Math.PI)).toFixed(4);
962 const yOuter = (0.5 + radiusOuter * Math.cos(progress * 2 * Math.PI)).toFixed(4);
963 const xInner = (0.5 + radiusInner * Math.sin(progress * 2 * Math.PI)).toFixed(4);
964 const yInner = (0.5 + radiusInner * Math.cos(progress * 2 * Math.PI)).toFixed(4);
965 for(let segment of [0, 1]) {
966 let p = 'M' + xOuter + ',' + yOuter;
967 p += 'A' + radiusOuter + ',' + radiusOuter + ' 0 ' + ((progress >= 0.5) ? (1 - segment) : segment) + ' ' + (1 - segment) + ' .5,' + (0.5 + radiusOuter);
968 p += 'V' + (0.5 + radiusInner);
969 p += 'A' + radiusInner + ',' + radiusInner + ' 0 ' + ((progress >= 0.5) ? (1 - segment) : segment) + ' ' + segment + ' ' + xInner + ',' + yInner;
971 game.ui.hud.children[0].children[segment].setAttribute('d', p);
973 if(game.timeProgress > game.timeTotal - 0.5) {
974 game.ui.hud.style.opacity = Math.max(0, (game.timeTotal - game.timeProgress - 0.25) * 4).toFixed(2);
977 if(game.ui.root.querySelector('.ui-page.gameplay p')) {
978 game.ui.root.querySelectorAll('.ui-page.gameplay p').forEach(elem => elem.remove());
980 if(game.timeProgress / game.timeTotal >= 1.0) {
981 game.ui.reachedEnd = true;
982 game.var.endingEntryTrajectory.set(game.objects.feather.position.x, game.objects.feather.position.y, game.objects.feather.position.z);
983 game.var.endingEntryRotation.x = game.objects.feather.rotation.x;
984 game.var.endingEntryRotation.y = game.objects.feather.rotation.y;
985 game.var.endingEntryRotation.z = game.objects.feather.rotation.z;
986 game.var.endingExitRotation.set(-0.2, 0, -0.2);
987 game['fn'].moveToPage('endingcutscene', true);
990 if(game.settings['audio']['music'] > 0.0 && game.view.music && !game.view.music.isPlaying) {
991 const remainingRealTime = (game.timeTotal - game.timeProgress) / (game.settings['difficulty']['speed'] / 100);
992 if(remainingRealTime >= game.assets['audio']['music-' + game.settings['audio']['theme']].duration - 2) {
993 game.view.music.offset = 0;
994 if(!game.view.muted) {
995 game.view.music.play();
1000 const angle = 2 * Math.PI * (game.timeProgress / game.timeTotal);
1001 game.view.camera.position.x = game.courseRadius * Math.sin(angle);
1002 game.view.camera.position.y = - game.courseRadius * Math.cos(angle);
1004 if(!game.settings['highcontrast']) {
1005 let sunsetValue = 2.0;
1006 if(!game.ui.reachedEnd) {
1007 sunsetValue = sunsetValue * game['fn'].easeInOut(Math.min(1, Math.max(0, ((game.timeProgress / game.timeTotal) - 0.3) / 0.6)));
1009 if(game.settings['graphics'] <= 2) {
1010 for(let i = 0; i < 6; i++) {
1011 game.view.materials['cloud' + i].uniforms.lerp.value = sunsetValue;
1014 let cloudMaterialVariant = null;
1015 if(sunsetValue < 0.5 && !game.objects.clouds.children[0].material.name.endsWith('a')) {
1016 cloudMaterialVariant = 'a';
1017 } else if(sunsetValue >= 0.5 && sunsetValue < 1.5 && !game.objects.clouds.children[0].material.name.endsWith('b')) {
1018 cloudMaterialVariant = 'b';
1019 } else if(sunsetValue >= 1.5 && !game.objects.clouds.children[0].material.name.endsWith('c')) {
1020 cloudMaterialVariant = 'c';
1022 if(cloudMaterialVariant) {
1023 for(let cloud of game.objects.clouds.children) {
1024 cloud.material = game.view.materials[cloud.material.name.slice(0, -1) + cloudMaterialVariant];
1026 game.objects.backdrop.material = game.view.materials['cloud0' + cloudMaterialVariant];
1031 if(game.timeProgress / game.timeTotal > 0.5 && game.objects.dayHouse.parent == scene) {
1032 scene.remove(game.objects.dayHouse);
1033 scene.add(game.objects.eveningHouse);
1036 game.var.featherLocalPos.subVectors(game.objects.feather.position, game.view.camera.position).setZ(0);
1037 game.var.featherBorderForce.set(0, 0, 0);
1038 for(let coord of [0, 1]) {
1039 if(Math.abs(game.var.featherLocalPos.getComponent(coord)) > 3) {
1040 game.var.featherBorderForce.setComponent(coord, 3 * Math.sign(game.var.featherLocalPos.getComponent(coord)) - game.var.featherLocalPos.getComponent(coord));
1043 game['fn'].applyForceToFeather(game.var.featherBorderForce);
1044 const tiltedGravity = game.gravity.clone();
1045 game.var.pinwheelDistance.subVectors(game.objects.feather.position, game.objects.pinwheel.position).setZ(0);
1047 const pinwheelRotationTargetSpeed = 1 + Math.max(0, 2 - game.var.pinwheelDistance.length());
1048 game.var.pinwheelRotationSpeed = Math.max(1, pinwheelRotationTargetSpeed, game.var.pinwheelRotationSpeed - 2 * delta);
1049 game.objects.pinwheel.rotation.z -= game.var.pinwheelRotationSpeed * 5 * delta;
1050 game.objects.pinwheel.position.x = game.view.camera.position.x + game.controls.positionX;
1051 game.objects.pinwheel.position.y = game.view.camera.position.y + game.controls.positionY;
1053 const pinwheelForce = 0.5 * Math.max(0, Math.pow(game.var.pinwheelDistance.length(), - 0.5) - 0.5);
1054 game['fn'].applyForceToFeather(game.var.pinwheelDistance.normalize().multiplyScalar(pinwheelForce));
1055 if(pinwheelForce < 0.2) {
1056 if(game.objects.feather.swayDirection > 0 && game.objects.feather.speed.x > 1.5) {
1057 game.objects.feather.swayDirection *= -1;
1058 } else if(game.objects.feather.swayDirection < 0 && game.objects.feather.speed.x < -1.5) {
1059 game.objects.feather.swayDirection *= -1;
1061 tiltedGravity.x += game.objects.feather.swayDirection;
1063 if(game.objects.feather.speed.y > -1) {
1064 game['fn'].applyForceToFeather(tiltedGravity);
1066 game.objects.feather.rotation.z = -0.1 * game.objects.feather.speed.x * game.settings['difficulty']['speed'] / 100;
1067 game.objects.feather.position.addScaledVector(game.objects.feather.speed, delta * game.settings['difficulty']['speed'] / 100);
1069 if(pinwheelForce > 0.2) {
1070 if(game.objects.feather.twistSpeed < 0.0001) {
1071 game.objects.feather.twistSpeed = (Math.random() - 0.5) * 0.01;
1073 game.objects.feather.twistSpeed = Math.sign(game.objects.feather.twistSpeed) * 0.1 * game.objects.feather.speed.length();
1075 game.objects.feather.twistSpeed = 0.98 * game.objects.feather.twistSpeed;
1076 if(Math.abs(game.objects.feather.twistSpeed < 0.1)) {
1077 let rotationDelta = game.objects.feather.rotation.x;
1078 if(rotationDelta >= Math.PI) {
1079 rotationDelta -= 2 * Math.PI;
1081 game.objects.feather.twistSpeed -= rotationDelta * 0.02;
1085 game.objects.feather.twistSpeed = Math.min(0.13, game.objects.feather.twistSpeed) * game.settings['difficulty']['speed'] / 100;
1086 game.objects.feather.rotation.x = (game.objects.feather.rotation.x + game.objects.feather.twistSpeed) % (2 * Math.PI);
1088 let collectedScale = 0.0;
1089 if(!game.settings['highcontrast'] && game.settings['graphics'] <= 2) {
1090 collectedScale = game['fn'].lerp(0.6, 0.3, 1 - Math.pow(1 - game.objects.words.collectedCount / game.objects.words.length, 2));
1091 } else if(!game.settings['highcontrast'] && game.settings['graphics'] == 3) {
1092 collectedScale = 0.3;
1094 const collectingRadius = - 0.5 + 1.5 * game.settings['difficulty']['collectingradius'];
1095 for(let i = 0; i < game.objects.words.length; i++) {
1096 let word = game.objects.words[i];
1097 if(!word.collected && new THREE.Vector3().subVectors(word.position, game.objects.feather.position).length() < collectingRadius) {
1098 word.collected = game.view.clock.getElapsedTime();
1099 game.objects.words.collectedCount += 1;
1100 game.ui.hud.children[1].innerText = game.objects.words.collectedCount;
1101 game['fn'].playRandomSound();
1103 if(word.parent != game.view.scene) {
1104 // All that happens in here is the positional animation for the word, which
1105 // we can skip if it is no longer visible.
1109 let collectionAnimationDuration = 1.0;
1110 for(let j = 0; j < word.children.length; j++) {
1111 game.var.notCollectedPos.set(0, 0, 0);
1112 game.var.collectedPos.set(0, 0, 0);
1113 let letter = word.children[j];
1114 let animationProgress = (((game.timeProgress + 5 * word.randomAnimOffset) % 5) / 5 + j / 37) % 1;
1115 if(!word.collected || game.view.clock.getElapsedTime() - word.collected <= collectionAnimationDuration) {
1116 x = word.position.x;
1117 y = word.position.y;
1119 if(game.settings['graphics'] <= 2 && !game.settings['highcontrast']) {
1120 const wordAnimationRadius = 0.2;
1121 x += wordAnimationRadius * Math.cos(animationProgress * 5 * Math.PI * 2);
1122 y += wordAnimationRadius * Math.sin(animationProgress * 4 * Math.PI * 2);
1123 z += wordAnimationRadius * Math.sin(animationProgress * 6 * Math.PI * 2);
1125 game.var.notCollectedPos.set(x, y, z);
1127 if(word.collected) {
1128 if(!game.settings['highcontrast']) {
1129 x = game.objects.feather.scale.x * 0.5 * Math.cos(animationProgress * 1 * Math.PI * 2);
1130 y = 0.2 * Math.sin(animationProgress * 7 * Math.PI * 2);
1131 z = 0.2 * Math.cos(animationProgress * 7 * Math.PI * 2);
1132 x = x * Math.cos(game.objects.feather.rotation.z) - y * Math.sin(game.objects.feather.rotation.z);
1133 y = y * Math.cos(game.objects.feather.rotation.z) + x * Math.sin(game.objects.feather.rotation.z);
1134 x += game.objects.feather.position.x;
1135 y += game.objects.feather.position.y;
1136 z += game.objects.feather.position.z;
1138 x = game.objects.feather.position.x;
1139 y = game.objects.feather.position.y;
1140 z = game.objects.feather.position.z;
1142 game.var.collectedPos.set(x, y, z);
1144 if(game.var.notCollectedPos.length() > 0 && game.var.collectedPos.length() > 0) {
1145 let collectingProgress = game['fn'].easeInOut(Math.max(0.0, Math.min(1.0, (game.view.clock.getElapsedTime() - word.collected) / collectionAnimationDuration)));
1146 letter.position.lerpVectors(game.var.notCollectedPos, game.var.collectedPos, collectingProgress);
1147 let scale = game['fn'].lerp(1.0, collectedScale, collectingProgress);
1148 letter.scale.set(scale, scale, scale);
1149 } else if(game.var.notCollectedPos.length() > 0) {
1150 letter.position.set(game.var.notCollectedPos.x, game.var.notCollectedPos.y, game.var.notCollectedPos.z);
1151 } else if(game.var.collectedPos.length() > 0) {
1152 letter.position.set(game.var.collectedPos.x, game.var.collectedPos.y, game.var.collectedPos.z);
1153 if(game.settings['highcontrast']) {
1154 // Special case because in high contrast mode, collected words vanish entirely.
1155 game.view.scene.remove(word);
1158 letter.position.sub(word.position);
1159 if(!game.settings['highcontrast']) {
1160 let rotation = (game.timeProgress * 3 + 2 * Math.PI * word.randomAnimOffset) % (2 * Math.PI);
1161 letter.rotation.set(rotation + j, rotation + 2*j, rotation + 3*j);
1166 game.view.renderer.render(scene, game.view.camera);
1169 game['fn'].loadSettings = () => {
1171 'controls': null, // set during first time launch depending on device
1172 'virtualinputleft': false,
1178 'theme': null, // actual default value determined after asset loading
1182 'highcontrast': false,
1185 'collectingradius': 1,
1189 'up': ['ArrowUp', 'w'],
1190 'right': ['ArrowRight', 'd'],
1191 'down': ['ArrowDown', 's'],
1192 'left': ['ArrowLeft', 'a'],
1198 stored = window['localStorage'].getItem('upInTheAirGameSettings');
1199 game.ui.root.querySelector('.ui-page.options .warning.storage').style.display = 'none';
1201 game.ui.root.querySelector('.ui-page.options .warning.storage').style.display = 'block';
1204 let merge = (source, target) => {
1205 for(let k of Object.keys(source)) {
1206 if(source[k] != null && typeof(source[k]) == 'object' && typeof(target[k]) == 'object' && !Array.isArray(target[k])) {
1207 merge(source[k], target[k]);
1208 } else if(k in target) {
1209 target[k] = source[k];
1213 stored = JSON.parse(stored);
1214 merge(stored, settings);
1216 const ui = game.ui.root.querySelector('.ui-page.options');
1217 if(settings['controls']) {
1218 ui.querySelector('.controls input[value="' + settings['controls'] + '"]').checked = true;
1219 ui.querySelector('.controls .leftside input').checked = settings['virtualinputleft'];
1220 ui.querySelector('.controls .leftside').style.display = (['touchpad', 'thumbstick'].includes(settings['controls'])) ? 'block' : 'none';
1221 ui.querySelectorAll('.controls p span:not(.' + settings['controls'] + ')').forEach(span => span.style.display = 'none');
1222 ui.querySelector('.controls span.' + settings['controls']).style.display = 'block';
1224 ui.querySelector('.hud input[name="upInTheAirGame-hud"]').checked = settings['enablehud'];
1225 game.ui.hud.style.display = settings['enablehud'] ? 'flex' : 'none';
1226 ui.querySelector('.graphics input[value="' + settings['graphics'] + '"]').checked = true;
1227 for(let audioCategory of ['music', 'sounds']) {
1228 let newValue = Math.max(0, Math.min(100, Math.round(100 * settings['audio'][audioCategory])));
1229 game.ui.root.querySelectorAll('.ui-page .audio input[type=range].' + audioCategory).forEach((elem) => {
1230 elem.value = newValue;
1231 elem.parentNode.nextElementSibling.innerText = newValue;
1234 let audioThemeRadio = ui.querySelector('.audiotheme input[value="' + settings['audio']['theme'] + '"]');
1235 if(audioThemeRadio) {
1236 audioThemeRadio.checked = true;
1238 // Custom hash function that ensures our unlockables get stored in the same order,
1239 // regardless of the order in which they get unlocked.
1240 let miniHash = (input) => {
1241 return 4 * input.charCodeAt(0) + 0.1 * input.charCodeAt(1) + 3 * input.charCodeAt(2) + 2 * input.charCodeAt(3);
1243 settings['unlocks'].sort((u1, u2) => miniHash(u1) > miniHash(u2));
1244 for(let unlockedFeather of settings['unlocks']) {
1245 if(!game.ui.root.querySelector('.ui-page.options .feather input[value="' + unlockedFeather + '"]')) {
1246 let radio = document.createElement('input');
1247 radio.type = 'radio';
1248 radio.name = 'upInTheAirGame-feather';
1249 radio.value = unlockedFeather;
1250 let img = document.createElement('img');
1251 if(unlockedFeather == 'golden' || unlockedFeather == 'ghost') {
1252 img.src = game['deploymentOptions']['assetUrlPrefix'] + 'textures/feather-' + unlockedFeather + '.png';
1254 let unlock = game['fn'].unlockWithKey('NIbp2kW5' + unlockedFeather + 'e2ZDFl5Y');
1255 if(unlock && unlock['type'] == 'feather') {
1256 img.src = unlock['url'];
1261 img.alt = unlockedFeather[0].toUpperCase() + unlockedFeather.slice(1) + ' feather';
1262 let label = document.createElement('label');
1263 label.appendChild(radio);
1264 label.appendChild(img);
1265 game.ui.root.querySelector('.ui-page.options .feather').appendChild(label);
1268 if(!ui.querySelector('.feather input[value="' + settings['feather'] + '"]')) {
1269 settings['feather'] = 'blue';
1271 ui.querySelector('.feather input[value=' + settings['feather'] + ']').checked = true;
1272 ui.querySelector('input[value="highcontrast"]').checked = !!settings['highcontrast'];
1273 ui.querySelector('.font input[value=' + settings['font'] + ']').checked = true;
1274 ui.querySelector('.difficulty select.collectingradius option[value="' + settings['difficulty']['collectingradius'] + '"]').selected = true;
1275 ui.querySelector('.difficulty select.speed option[value="' + settings['difficulty']['speed'] + '"]').selected = true;
1276 for(let direction of ['up', 'right', 'down', 'left']) {
1277 let keys = settings['keyboard'][direction];
1278 let btn = ui.querySelector('.keyboard button.' + direction);
1279 btn.value = keys.join('|');
1280 keys = keys.map(k => {
1281 if(k.length == 1 && k != 'ß') {
1282 k = k.toUpperCase();
1285 case 'ArrowUp': return '🠕';
1286 case 'ArrowRight': return '🠖';
1287 case 'ArrowDown': return '🠗';
1288 case 'ArrowLeft': return '🠔';
1289 case ' ': return 'Space';
1293 btn.innerText = keys.join(' or ');
1295 ui.querySelector('input[value="tapmode"]').checked = !!settings['keyboard']['tapmode'];
1296 game.settings = settings;
1299 game['fn'].applySettings = () => {
1300 const ui = game.ui.root.querySelector('.ui-page.options');
1301 if(ui.querySelector('input[name="upInTheAirGame-controls"]:checked')) {
1302 game.settings['controls'] = ui.querySelector('input[name="upInTheAirGame-controls"]:checked').value;
1304 game.settings['virtualinputleft'] = ui.querySelector('.controls .leftside input').checked;
1305 if(game.settings['virtualinputleft']) {
1306 game.ui.root.parentNode.classList.add('virtual-input-left');
1308 game.ui.root.parentNode.classList.remove('virtual-input-left');
1310 const virtualInput = game.ui.root.parentNode.querySelector('.virtual-input-widget');
1311 virtualInput.children[0].style.display = 'block';
1312 virtualInput.children[0].style.left = '50%';
1313 virtualInput.children[0].style.top = '50%';
1314 delete virtualInput.inProgress;
1315 if(game.settings['controls'] == 'touchpad') {
1316 virtualInput.classList.remove('thumbstick');
1317 virtualInput.classList.add('touchpad');
1318 game.ui.root.classList.remove('control-mouse', 'control-thumbstick');
1319 game.ui.root.classList.add('control-touchpad');
1320 virtualInput.children[0].style.display = 'none';
1321 } else if(game.settings['controls'] == 'thumbstick') {
1322 virtualInput.classList.remove('touchpad');
1323 virtualInput.classList.add('thumbstick');
1324 game.ui.root.classList.remove('control-mouse', 'control-touchpad');
1325 game.ui.root.classList.add('control-thumbstick');
1326 } else if(game.settings['controls'] == 'mouse') {
1327 virtualInput.classList.remove('touchpad', 'thumbstick');
1328 game.ui.root.classList.remove('control-touchpad', 'control-thumbstick');
1329 game.ui.root.classList.add('control-mouse');
1331 virtualInput.classList.remove('touchpad', 'thumbstick');
1332 game.ui.root.classList.remove('control-mouse', 'control-touchpad', 'control-thumbstick');
1334 for(let timeout of [10, 100, 1000]) {
1335 setTimeout(() => { game.ui.root.style.fontSize = (game.ui.root.clientWidth / 48) + 'px'; }, timeout);
1337 game.settings['graphics'] = parseInt(ui.querySelector('input[name="upInTheAirGame-graphics"]:checked').value, 10);
1339 let resolution = Math.round(3200 / Math.pow(2, game.settings['graphics']));
1340 game.view.canvas.width = resolution;
1341 game.view.canvas.height = resolution;
1342 game.view.camera.updateProjectionMatrix();
1343 game.view.renderer.setSize(game.view.canvas.width, game.view.canvas.height);
1345 game.settings['enablehud'] = ui.querySelector('.hud input[name="upInTheAirGame-hud"]').checked;
1346 for(let audioCategory of ['music', 'sounds']) {
1347 game.settings['audio'][audioCategory] = parseInt(ui.querySelector('.audio input[type=range].' + audioCategory).value, 10) / 100;
1349 let audioThemeRadio = ui.querySelector('.audiotheme input[name="upInTheAirGame-audiotheme"]:checked');
1350 if(audioThemeRadio) {
1351 game.settings['audio']['theme'] = audioThemeRadio.value;
1353 game.settings['feather'] = ui.querySelector('input[name="upInTheAirGame-feather"]:checked').value;
1354 game.settings['highcontrast'] = ui.querySelector('input[value="highcontrast"]').checked;
1355 game.settings['font'] = ui.querySelector('input[name="upInTheAirGame-font"]:checked').value;
1356 game.settings['difficulty']['collectingradius'] = parseInt(ui.querySelector('.difficulty select.collectingradius').value, 10);
1357 game.settings['difficulty']['speed'] = parseInt(ui.querySelector('.difficulty select.speed').value, 10);
1358 for(let direction of ['up', 'right', 'down', 'left']) {
1359 game.settings['keyboard'][direction] = ui.querySelector('.keyboard button.' + direction).value.split('|');
1361 game.settings['keyboard']['tapmode'] = ui.querySelector('input[value="tapmode"]').checked;
1363 window['localStorage'].setItem('upInTheAirGameSettings', JSON.stringify(game.settings));
1364 game.ui.root.querySelector('.ui-page.options .warning.storage').style.display = 'none';
1366 game.ui.root.querySelector('.ui-page.options .warning.storage').style.display = 'block';
1369 for(let audioCategory of ['music', 'sounds']) {
1370 game.settings['audio'][audioCategory] = parseInt(ui.querySelector('.audio input[type=range].' + audioCategory).value, 10) / 100;
1371 let value = Math.round(100 * game.settings['audio'][audioCategory]);
1372 game.ui.root.querySelectorAll('.ui-page .audio input[type=range].' + audioCategory).forEach((elem) => {
1374 elem.parentNode.nextElementSibling.innerText = value;
1376 if(audioCategory == 'music' && game.view && game.view.music) {
1377 game.view.music.setVolume(game.settings['audio'][audioCategory]);
1380 game.ui.root.classList.remove('font-atkinson', 'font-opendyslexic');
1381 if(game.settings['font'] != 'standard') {
1382 game.ui.root.classList.add('font-' + game.settings['font']);
1386 game['fn'].createFeather = () => {
1387 let position, rotation;
1388 if(game.objects.feather) {
1389 position = game.objects.feather.position;
1390 rotation = game.objects.feather.rotation;
1391 game.objects.feather.geometry.dispose();
1392 game.objects.feather.material.dispose();
1393 game.view.scene.remove(game.objects.feather);
1394 delete game.objects.feather;
1397 const featherGeometry = new THREE.PlaneGeometry(1.6, 0.5);
1399 map: game.assets.textures['feather-' + game.settings['feather']],
1402 side: THREE.DoubleSide,
1404 if(game.settings['feather'] == 'golden') {
1405 options.color = 0xffffff;
1406 options.emissive = 0x644a1e;
1407 options.roughness = 0.5;
1408 options.metalness = 0.4;
1410 if(game.settings['feather'] == 'ghost') {
1411 options.opacity = 0.7;
1413 game.view.materials.feather = new THREE.MeshStandardMaterial(options);
1414 game.objects.feather = new THREE.Mesh(featherGeometry, game.view.materials.feather);
1415 game.objects.feather.rotation.order = 'ZXY';
1417 game.objects.feather.position.set(position.x, position.y, position.z);
1420 game.objects.feather.rotation.set(rotation.x, rotation.y, rotation.z);
1422 game.view.scene.add(game.objects.feather);
1423 game.objects.feather.speed = new THREE.Vector3(0, 0, 0);
1424 game.gravity = new THREE.Vector3(0, -0.1, 0);
1425 game.objects.feather.swayDirection = 0.2;
1426 game.objects.feather.twistSpeed = 0.1;
1429 game['fn'].createMeshes = () => {
1430 if(game.objects.clouds && game.objects.clouds.parent == game.view.scene) {
1431 game.view.scene.remove(game.objects.clouds);
1432 if(game.objects.clouds.children.length > 0) {
1433 game.objects.clouds.children[0].geometry.dispose();
1435 for(let mKey in game.view.materials) {
1436 game.view.materials[mKey].dispose();
1438 delete game.objects.clouds;
1440 if(game.objects.backdrop && game.objects.backdrop.parent == game.view.scene) {
1441 game.view.scene.remove(game.objects.backdrop);
1442 game.objects.backdrop.material.dispose();
1443 game.objects.backdrop.geometry.dispose();
1445 if(game.assets.fonts.geometry) {
1446 for(let geom of Object.values(game.assets.fonts.geometry)) {
1447 if(geom.customMaterial) {
1448 geom.customMaterial.dispose();
1452 delete game.assets.fonts.geometry;
1454 if(game.view.materials) {
1455 for(let material of Object.values(game.view.materials)) {
1458 delete game.view.materials;
1461 if(game.view.materials && game.view.materials.feather) {
1462 game.view.materials = {
1463 'feather': game.view.materials['feather'],
1466 game.view.materials = {};
1469 if(!game.settings['highcontrast']) {
1471 let cloudGeometry = new THREE.PlaneGeometry(1, 200 / 350);
1472 if(game.settings['graphics'] <= 2) {
1476 precision highp float;
1477 precision highp int;
1481 gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
1486 precision mediump float;
1487 uniform sampler2D texture1;
1488 uniform sampler2D texture2;
1489 uniform sampler2D texture3;
1494 vec4 col1 = texture2D(texture2, vUv);
1495 vec4 col2 = texture2D(texture3, vUv);
1496 gl_FragColor = mix(col1, col2, lerp - 1.0);
1498 vec4 col1 = texture2D(texture1, vUv);
1499 vec4 col2 = texture2D(texture2, vUv);
1500 gl_FragColor = mix(col1, col2, lerp);
1502 // I don't know how GLSL works: why do I need to do this to match the textures?
1503 gl_FragColor = mix(gl_FragColor, vec4(1.0, 1.0, 1.0, gl_FragColor.a), 0.5);
1508 for(let i = 0; i < 6; i++) {
1509 if(game.settings['graphics'] <= 2) {
1510 game.view.materials['cloud' + i] = new THREE.ShaderMaterial({
1511 uniforms: THREE.UniformsUtils.merge([{
1519 game.view.materials['cloud' + i].uniforms.texture1.value = game.assets.textures['cloud' + i + 'a'];
1520 game.view.materials['cloud' + i].uniforms.texture2.value = game.assets.textures['cloud' + i + 'b'];
1521 game.view.materials['cloud' + i].uniforms.texture3.value = game.assets.textures['cloud' + i + 'c'];
1522 if(game.ui.reachedEnd) {
1523 game.view.materials['cloud' + i].uniforms.lerp.value = 2.0;
1525 game.view.materials['cloud' + i].uniforms.lerp.value = 0.0;
1527 game.view.materials['cloud' + i].transparent = true;
1529 for(let variant of ['a', 'b', 'c']) {
1530 game.view.materials['cloud' + i + variant] = new THREE.MeshBasicMaterial({
1531 map: game.assets.textures['cloud' + i + variant],
1535 game.view.materials['cloud' + i + variant].name = 'cloud' + i + variant;
1539 game.objects.clouds = new THREE.Group();
1540 let textureVariantSuffix = '';
1541 if(game.settings['graphics'] > 2) {
1542 if(game.ui.reachedEnd) {
1543 textureVariantSuffix = 'c';
1545 textureVariantSuffix = 'a';
1548 game.view.materials.letter = new THREE.MeshStandardMaterial({
1554 if(game.settings['graphics'] <= 2) {
1555 game.assets.fonts.geometry = {};
1556 for(let letter of [...new Set(game.assets.wordList.join(''))]) {
1557 if(game.settings['graphics'] == 1) {
1558 game.assets.fonts.geometry[letter] = new TextGeometry(letter, {
1559 font: game.assets.fonts.cookie,
1563 bevelEnabled: false,
1565 game.assets.fonts.geometry[letter].computeBoundingBox();
1566 let bbox = game.assets.fonts.geometry[letter].boundingBox;
1567 // Add these to local 0,0 later to get the letter's center rotation point
1568 game.assets.fonts.geometry[letter].dx = (bbox.max.x - bbox.min.x) / 2;
1569 game.assets.fonts.geometry[letter].dy = (bbox.max.y - bbox.min.y) / 2;
1571 let letterCanvas = document.createElement('canvas');
1572 letterCanvas.width = 64;
1573 letterCanvas.height = 64;
1574 let letterCanvasContext = letterCanvas.getContext('2d');
1575 letterCanvasContext.font = '60px Cookie';
1576 letterCanvasContext.fillStyle = '#000';
1577 letterCanvasContext.fillRect(0, 0, letterCanvas.width, letterCanvas.height);
1578 letterCanvasContext.fillStyle = '#fff';
1579 let bbox = letterCanvasContext.measureText(letter);
1580 let vOffset = bbox.actualBoundingBoxAscent - 0.5 * (bbox.actualBoundingBoxAscent + bbox.actualBoundingBoxDescent);
1581 letterCanvasContext.fillText(letter, Math.round((letterCanvas.width - bbox.width) / 2), (letterCanvas.height / 2) + vOffset);
1582 let alphaMap = new THREE.CanvasTexture(letterCanvas);
1583 alphaMap.needsUpdate = true;
1584 let letterMaterial = new THREE.MeshStandardMaterial({
1585 color: game.view.materials.letter.color,
1587 roughness: game.view.materials.letter.roughness,
1588 metalness: game.view.materials.letter.metalness,
1589 side: THREE.DoubleSide,
1593 game.assets.fonts.geometry[letter] = new THREE.PlaneGeometry(0.3, 0.3);
1594 game.assets.fonts.geometry[letter].dx = 0;
1595 game.assets.fonts.geometry[letter].dy = 0;
1596 game.assets.fonts.geometry[letter].customMaterial = letterMaterial;
1599 let numClouds = 300;
1600 if(game.settings['graphics'] == 2) {
1603 for(let i = 0; i < numClouds; i++) {
1604 let randomAngle = Math.random() * 2 * Math.PI;
1605 let randomCameraX = game.courseRadius * Math.sin(randomAngle);
1606 let randomCameraY = game.courseRadius * Math.cos(randomAngle);
1607 let cloud = new THREE.Mesh(cloudGeometry, game.view.materials['cloud' + (i % 5 + 1) + textureVariantSuffix]);
1608 cloud.position.z = -15 - Math.round(Math.random() * 40);
1609 const vFOV = THREE.MathUtils.degToRad(game.view.camera.fov);
1610 let maxCameraDistance = 2 * Math.tan(vFOV / 2) * Math.abs(cloud.position.z - game.view.camera.position.z);
1611 cloud.position.x = randomCameraX + maxCameraDistance * 2 * (Math.random() - 0.5);
1612 cloud.position.y = randomCameraY + maxCameraDistance * 2 * (Math.random() - 0.5);
1613 let scale = 21 + (Math.random() * 0.5 + 0.5) * Math.abs(cloud.position.z);
1614 cloud.scale.set(scale, scale, scale);
1615 game.objects.clouds.add(cloud);
1618 const minimalLetterGeometry = new THREE.BoxGeometry(0.2, 0.2, 0.2);
1619 minimalLetterGeometry.dx = 0;
1620 minimalLetterGeometry.dy = 0;
1621 game.assets.fonts.geometry = {};
1622 for(let letter of [...new Set(game.assets.wordList.join(''))]) {
1623 game.assets.fonts.geometry[letter] = minimalLetterGeometry;
1625 for(let r = 0; r < game.courseRadius / 3; r++) {
1626 let angle = THREE.MathUtils.degToRad(360 * 3 * r / game.courseRadius);
1627 let cameraX = game.courseRadius * Math.sin(angle);
1628 let cameraY = game.courseRadius * Math.cos(angle);
1629 const vFOV = THREE.MathUtils.degToRad(game.view.camera.fov);
1631 let maxCameraDistance = Math.tan(vFOV / 2) * Math.abs(z - game.view.camera.position.z);
1632 let axis = [-1, 0, 1];
1636 for(let step of axis) {
1637 let shape = 1 + Math.floor(Math.random() * 5);
1638 let cloud = new THREE.Mesh(cloudGeometry, game.view.materials['cloud' + shape + textureVariantSuffix]);
1639 cloud.position.x = cameraX + step * 1.2 * maxCameraDistance * Math.sin(angle);
1640 cloud.position.y = cameraY + step * maxCameraDistance * Math.cos(angle);
1641 cloud.position.z = z;
1642 let scale = 15 + 0.5 * Math.abs(cloud.position.z);
1643 cloud.scale.set(scale, scale, scale);
1644 game.objects.clouds.add(cloud);
1648 game.view.scene.add(game.objects.clouds);
1649 game.objects.backdrop = new THREE.Mesh(new THREE.PlaneGeometry(350, 350), game.view.materials['cloud0' + textureVariantSuffix]);
1650 game.objects.backdrop.position.setZ(-100);
1652 game.view.materials.letter = new THREE.MeshStandardMaterial({
1656 const highcontrastLetterGeometry = new THREE.SphereGeometry(0.1, 16, 16);
1657 highcontrastLetterGeometry.dx = 0;
1658 highcontrastLetterGeometry.dy = 0;
1659 game.assets.fonts.geometry = {};
1660 for(let letter of [...new Set(game.assets.wordList.join(''))]) {
1661 game.assets.fonts.geometry[letter] = highcontrastLetterGeometry;
1663 const highContrastBackdropMaterial = new THREE.MeshBasicMaterial({
1664 map: game.assets.textures['highcontrast-backdrop'],
1666 game.objects.backdrop = new THREE.Mesh(new THREE.PlaneGeometry(150, 150), highContrastBackdropMaterial);
1667 game.objects.backdrop.position.setZ(-10);
1669 if(game.objects.words) {
1670 for(let word of game.objects.words) {
1671 game['fn'].prepareWordMesh(word);
1674 game.view.scene.add(game.objects.backdrop);
1677 game['fn'].unlockFeather = (feather, url) => {
1678 if(game.settings['unlocks'].includes(feather)) {
1681 game.settings['unlocks'].push(feather);
1683 url = game['deploymentOptions']['assetUrlPrefix'] + 'textures/feather-' + feather + '.png';
1684 } else if(url.startsWith('textures/')) {
1685 url = game['deploymentOptions']['assetUrlPrefix'] + url;
1688 if(!game.assets['textures']['feather-' + feather]) {
1689 (new THREE.TextureLoader()).load(url, (result) => {
1690 result.colorSpace = THREE.SRGBColorSpace;
1691 result.minFilter = THREE.NearestFilter;
1692 result.magFilter = THREE.NearestFilter;
1693 result.repeat = new THREE.Vector2(1, -1);
1694 result.wrapT = THREE.RepeatWrapping;
1695 game.assets['textures']['feather-' + feather] = result;
1696 }, () => {}, (err) => {
1697 console.error('Error while loading ' + feather + ' feather texture: ' + err);
1700 // Custom hash function that ensures our unlockables get stored in the same order,
1701 // regardless of the order in which they get unlocked.
1702 let miniHash = (input) => {
1703 return 4 * input.charCodeAt(0) + 0.1 * input.charCodeAt(1) + 3 * input.charCodeAt(2) + 2 * input.charCodeAt(3);
1705 game.settings['unlocks'].sort((u1, u2) => miniHash(u1) > miniHash(u2));
1706 let insertAfterFeather = 'purple';
1707 if(game.settings['unlocks'].indexOf(feather) >= 1) {
1708 insertAfterFeather = game.settings['unlocks'][game.settings['unlocks'].indexOf(feather) - 1];
1710 let radio = document.createElement('input');
1711 radio.type = 'radio';
1712 radio.name = 'upInTheAirGame-feather';
1713 radio.value = feather;
1714 radio.addEventListener('change', () => {
1715 game['fn'].applySettings();
1716 game['fn'].createFeather();
1718 let img = document.createElement('img');
1720 img.alt = feather[0].toUpperCase() + feather.slice(1) + ' feather';
1721 let label = document.createElement('label');
1722 label.appendChild(radio);
1723 label.appendChild(img);
1724 game.ui.root.querySelector('.ui-page.options .feather input[value="' + insertAfterFeather + '"]').parentNode.after(label);
1725 game['fn'].applySettings();
1726 let ui = game.ui.root.querySelector('.ui-page.unlock');
1727 let img2 = ui.querySelector('img');
1730 ui.querySelector('p.name').innerText = img2.alt;
1734 game['fn'].moveToPage = (target, skipFade = false) => {
1735 let fadeDuration = 250;
1739 // After the gameplay page is shown for the first time, always keep it around as a backdrop
1740 game.ui.root.querySelectorAll('.ui-page:not(.' + target + '):not(.gameplay)').forEach((page) => {
1741 page.style.opacity = '0';
1742 setTimeout((page) => {
1743 page.style.display = 'none';
1744 }, fadeDuration, page);
1746 if(game.ui.currentPage == 'title' && !game.ui.reachedStart) {
1748 game.ui.root.querySelector('.ui-page.title h1').removeAttribute('style');
1749 game.ui.root.querySelectorAll('.ui-page.title button').forEach(btn => { btn.disabled = false; btn.removeAttribute('style'); });
1750 game.ui.root.querySelector('.ui-page.title .footer').removeAttribute('style');
1751 game.ui.root.querySelector('.ui-page.title .system-buttons').removeAttribute('style');
1752 game.ui.reachedStart = true;
1755 if(target == 'title' && game.view) {
1756 game.view.cheatBuffer = '';
1758 if(target == 'title' && (!game.ui.currentPage || ['loading', 'controls'].includes(game.ui.currentPage))) {
1759 game['fn'].initializeGame(game.ui.root.querySelector('canvas'));
1761 if(target == 'title' && game.ui.root.querySelector('.ui-page.gameplay p')) {
1762 game.ui.root.querySelectorAll('.ui-page.gameplay p').forEach(elem => elem.remove());
1764 if(target == 'title' && game.view && game.view.windSound && game.view.windSound.isPlaying) {
1765 game.view.windSound.stop();
1767 if(target == 'title' && game.view && game.view.music && game.view.music.isPlaying) {
1768 game.view.music.stop();
1769 if(game.view.music.timeoutID) {
1770 clearTimeout(game.view.music.timeoutID);
1771 delete game.view.music.timeoutID;
1774 if((target != 'pause' && game.ui.currentPage != 'pause') || target == 'title') {
1775 game.ui.hud.style.opacity = '0';
1777 if(target == 'outro') {
1778 if(game.view.music.isPlaying) {
1779 game.view.music.stop();
1781 let collectedWords = game.objects.words.filter(w => w.collected).map(w => w.text);
1782 game.ui.root.querySelector('.ui-page.outro .count').innerText = game.objects.words.collectedCount;
1783 game.ui.root.querySelector('.ui-page.outro .optionalPlural').innerText = 'word' + ((game.objects.words.collectedCount == 1) ? '' : 's') + '.';
1784 let ratingElem = game.ui.root.querySelector('.ui-page.outro .rating');
1785 let exampleElems = game.ui.root.querySelectorAll('.ui-page.outro .examples');
1786 let finalParagraph = game.ui.root.querySelector('.ui-page.outro .area > p:last-child');
1787 ratingElem.style.display = 'none';
1788 exampleElems.forEach(elem => { elem.style.display = 'none'; });
1789 let returnButton = game.ui.root.querySelector('.ui-page.outro button.goto');
1790 if(game.objects.words.collectedCount == 100 || game.objects.words.collectedCount == 0) {
1791 finalParagraph.style.display = 'none';
1792 let neededUnlocking = false;
1793 if(game.objects.words.collectedCount == 100) {
1794 neededUnlocking = game['fn'].unlockFeather('golden');
1796 neededUnlocking = game['fn'].unlockFeather('ghost');
1798 if(neededUnlocking) {
1799 returnButton.innerText = 'Continue';
1800 returnButton.classList.remove('title');
1801 returnButton.classList.add('unlock');
1803 returnButton.innerText = 'Return to Title Screen';
1804 returnButton.classList.remove('unlock');
1805 returnButton.classList.add('title');
1808 finalParagraph.style.display = 'block';
1809 returnButton.innerText = 'Return to Title Screen';
1810 returnButton.classList.remove('unlock');
1811 returnButton.classList.add('title');
1813 if(game.objects.words.collectedCount > 0) {
1814 if(game.objects.words.collectedCount == 100) {
1815 ratingElem.style.display = 'block';
1816 ratingElem.innerText = 'Wow, you managed to collect all of them. Congratulations!';
1818 let generateExampleSentences = (wordList) => {
1819 let container = game.ui.root.querySelector('.ui-page.outro div.examples');
1820 while(container.children.length > 0) {
1821 container.children[0].remove();
1824 for(let category of Object.keys(game.assets.words)) {
1825 words[category] = [];
1826 for(let word of game.assets.words[category]) {
1827 if(wordList.includes(word)) {
1828 words[category].push(word);
1833 let failedAttempts = 0;
1834 while(result.length < 3 && failedAttempts < 1000) {
1835 let sentence = game.assets.sentences[Math.floor(Math.random() * game.assets.sentences.length)];
1836 while(sentence.indexOf('{') > -1) {
1837 let areWeStuck = true;
1838 for(let category of Object.keys(words)) {
1839 if(sentence.includes('{' + category + '}')) {
1840 if(words[category].length == 0) {
1843 let choice = words[category][Math.floor(Math.random() * words[category].length)];
1844 if(category == 'sorry') {
1845 if(choice == 'sorry') {
1846 sentence = sentence.replace('{sorry}', 'I’m {sorry}');
1848 if(choice == 'apologize') {
1849 sentence = sentence.replace('{sorry}', 'I {sorry}');
1852 if(sentence.indexOf('{' + category + '}') == 0) {
1853 choice = choice[0].toUpperCase() + choice.slice(1);
1855 sentence = sentence.replace('{' + category + '}', '<strong>' + choice + '</strong>');
1856 words[category].splice(words[category].indexOf(choice), 1);
1864 if(sentence.indexOf('{') == -1 && !result.includes(sentence)) {
1865 result.push(sentence);
1868 failedAttempts += 1;
1870 for(let sentence of result) {
1871 let elem = document.createElement('p');
1872 elem.innerHTML = sentence;
1873 container.appendChild(elem);
1876 generateExampleSentences(collectedWords);
1877 game.ui.root.querySelector('.ui-page.outro button.examples').addEventListener('click', () => { generateExampleSentences(collectedWords); });
1878 exampleElems.forEach(elem => { elem.style.display = 'flex'; });
1881 ratingElem.style.display = 'block';
1882 ratingElem.innerText = 'You completed the course while dodging every word. That’s an achievement all on its own. Respect!';
1885 if(target == 'options') {
1886 game.ui.root.querySelectorAll('.options .areatabs button').forEach((btn) => {
1887 if(btn.classList.contains('general')) {
1888 btn.classList.add('active');
1890 btn.classList.remove('active');
1893 game.ui.root.querySelectorAll('.options > div.area.twocol').forEach((area) => {
1894 if(area.classList.contains('general')) {
1895 area.style.display = 'flex';
1897 area.style.display = 'none';
1901 const targetElems = [game.ui.root.querySelector('.ui-page.' + target + '')];
1902 if(game.ui.root.querySelector('.ui-page.gameplay').style.opacity != '1' && target == 'title') {
1903 targetElems.push(game.ui.root.querySelector('.ui-page.gameplay'));
1905 for(let targetElem of targetElems) {
1906 if(!targetElem.classList.contains('gameplay')) {
1907 targetElem.style.opacity = '0';
1909 targetElem.style.display = 'flex';
1910 setTimeout((targetElem) => {
1911 targetElem.style.opacity = '1';
1912 if(target == 'credits') {
1913 targetElem.querySelector('.area').scrollTop = 0;
1915 }, fadeDuration, targetElem);
1917 if(target != 'pause' && game.ui.currentPage != 'pause') {
1918 game.timeProgress = 0;
1920 if(target == 'pause') {
1921 game.view.music.stop();
1922 game.view.windSound.stop();
1923 } else if(game.ui.currentPage == 'pause' && target == 'openingcutscene') {
1924 if(game.timeProgress >= 1.0) {
1925 game.view.windSound.offset = game.timeProgress - 1.0;
1926 game.view.windSound.setVolume(game.settings['audio']['sounds']);
1927 if(!game.view.muted) {
1928 game.view.windSound.play();
1931 } else if(game.ui.currentPage == 'pause' && target == 'gameplay') {
1932 game.view.music.offset = (game.timeProgress / (game.settings['difficulty']['speed'] / 100)) % game.assets['audio']['music-' + game.settings['audio']['theme']].duration;
1933 if(!game.view.muted) {
1934 game.view.music.play();
1937 game.ui.previousPage = game.ui.currentPage;
1938 game.ui.currentPage = target;
1940 game.startTime = game.view.clock.getElapsedTime();
1944 game['fn'].unlockWithKey = (input) => {
1945 input = 'aBYPmb2xCwF2ilfD'+ input + 'PNHFwI2zKZejUv6c';
1946 let hash = (input) => {
1947 // Adapted with appreciation from bryc:
1948 // https://github.com/bryc/code/blob/master/jshash/experimental/cyrb53.js
1949 let h1 = 0xdeadbeef, h2 = 0x41c6ce57;
1950 for(let i = 0, ch; i < input.length; i++) {
1951 ch = input.charCodeAt(i);
1952 h1 = Math.imul(h1 ^ ch, 2654435761);
1953 h2 = Math.imul(h2 ^ ch, 1597334677);
1955 h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
1956 h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
1957 h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
1958 h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
1959 return (h2 >>> 0).toString(16).padStart(8, 0) + (h1 >>> 0).toString(16).padStart(8, 0);
1961 for(let unlockable of game.unlockables) {
1962 if(unlockable.accessKey == hash(input)) {
1963 let key = hash('UZx2jWen9w5jm0FB' + input + '7DZpEq4OOwv2kiJ1');
1964 let seed = parseInt(key.slice(12), 16);
1967 seed = seed + 0x9e3779b9 | 0;
1968 let t = seed ^ seed >>> 16;
1969 t = Math.imul(t, 0x21f0aaad);
1971 t = Math.imul(t, 0x735a2d97);
1972 return ((t = t ^ t >>> 15) >>> 0);
1974 let data = Uint8Array.from(atob(unlockable['payload']), (c) => c.codePointAt(0));
1976 for(let i = 0; i < data.length; i++) {
1979 pad = [pad % 256, (pad >> 8) % 256, (pad >> 16) % 256, (pad >> 24) % 256];
1981 data[i] = data[i] ^ pad[i % 4];
1983 data = new TextDecoder().decode(data);
1984 let result = JSON.parse(data);
1985 if(result['type'] == 'redirect') {
1986 return game['fn'].unlockWithKey(result['target']);
1995 game['fn'].start = () => {
1997 root: document.querySelector('.upInTheAirGame .ui-container'),
1998 hud: document.querySelector('.upInTheAirGame .gameplay .hud'),
2002 // If you're looking at the source code and the following seems scary, don't worry, it's just a few
2003 // unlockable feather textures. I liked easter eggs and cheat codes when I was young, and I didn't
2004 // want these to be trivially bypassable for people who can read the code.
2005 game.unlockables = [
2007 'accessKey': '5b32eb7ad08488f4',
2008 'payload': 'k4JPu3sWfEhcgleieVGghixKSI10qdRRC5tAl39Tzy1U7Rx9EEEYbLx9wCcxAf7wC8r9mJZCOj8bNa7grMbUmTeCeWWPAg==',
2011 'accessKey': '6273da5894b2dd8b',
2012 'payload': 'XAFLhAjcTzsWgGb7DAMCKwHXjoyUg/yxkIUyLcV/7PpktgW3MHtXhh4OkVeANr52RfdbwfVpgO4dxuyYPaFZ4x4JDmI=',
2015 'accessKey': 'fb8b533451a6dd68',
2016 'payload': 'u2QtZwORGGkQsXRmPeJK2nUgxhFQSr7ewqLAC6l6lVXRShEVVpiqFZIf0y5MfnVptVHCxAuNZZF2sbc6LFxEBojTMI1R2tQfY7MEMYxs5Wi3/lsp53Xu3ASRd+N5aTemajx+56hiOtiLgqU5xhN9sq4qNgqj+y864VJJ/vFBYdtO7d5bhAU5TT1CK8K4uC+i8TDQL3BL4ykw8lQgRkImEsXnckBa9HORqt7/Tbp7KLiw2fGOBYDvdDTz2VmfiDaW7out8PSmUdBzti+DlWh/gTJ+LhU7pIhn943H08vGsXB3WjA0WAof/27BdhCCjGbVypBYv/f8lgAtBienoaT5Ckzth6AlUrFPwrxvb/5uagEfgzl8ziyMilhEe48Ef6gQQ8SqzFlH1RuxjtVcIdaP2gqgLCTkSSuw8tfVq6bu2wFoMoBtqcjT0qc6tUU9TRSGchOxq3l6tnLr7IvPbCTUdEMskWUfm1QRlWjxZKDEtPhiEz41QoAEX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KCQFExo16e3+w41MLEPx159H1+Wvxa8Zx6Y0D9Ojr7OouRg7rKlnJAzU/om73eb/numkzKzJQ7nLV5N3TSyUyw2FdfKn08Hekwbl1F+PGbyg/tSTx3xmyISBT9pGL9byrXpYMVHSVT+8oyeudhgF94wZSaYv2JhtQ+Ua6Om8T9Xi/o+TR11oR9gVVKTd0fzzKsrVMrIbu995Ao6NEXmIITEKloTj5SvMByufXHZwz7EloVfNQjxL8jq25ffMfIjCF336baIpiQpw4Cq43uQBtJNfbewT51zySeIhRQExJBGwdbBsORGgqZZxv8lJdEcP7SKXiRZay5YqKVeHnSXXyTEr5poF7sbieiiO9We2MH7pHNNJrMQtvWkMUHYRt6WXl00WBtDwuE6KZYAsTcscw/S+P4oiDs2zE42FilQZCwR+JY8bHpoW0AyMAEVzbpVtbOYUAt4/hW2Ye18Tun9nKyb0O8rhzE1iutQQC5FfUeqwrQ1x/jbHAoujJA9hUXAhmQEfaTb2Dyh1Ai4wfBWhDGRnlr8WXAdrPrLCoJiadE/DS6gDgId1xrF6wL5yKht46KapK48hmNkDftMn1uNMcq4N2l9g/Z3KOEo+xmwP9AYZgSoiLZsrh/CR6lVqL80poB2tz2pHh+cIGgK/KhtwxchA0D2ixOdqJMDJrWiKXBRTcX3CgpFR9vcMPItj/wb21jIeZuG1z+k+sAN5wrkgPmSRnqw=',
2019 'accessKey': '3c78e25c7b1106b6',
2020 'payload': 'dnbO28tXI2i2+o+etuRc0/Cfxd4UpdG1IRgqB0fTwJE1xCoK+TtB/JVGTquaD/stnIkKiA==',
2023 'accessKey': '5f79141f861a146a',
2024 'payload': 'IO59sEgiVtdv68PW1n+NdmYY6sGhOdG6BHA4BwVErVCIu25lohqBbDKgI+gWyCPVFUaFk76yW1Ji09i/n+swIQK5ayyfCeRoruxz2lA/Eoe0LTPqy2CPShxD0Pfi66AdgzQ+jMvHOi9Stw/t0XGGpLjrQfghJDnZpuEgipYG3PpiZbcbj3BVUuw7fV6idwGPBXoqagwXvscfjQppTq8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RFw+VxYMJj+65MDbbJn77ar/DmcxIg7HaZnpZhFe2Uepsqo3IOsG/3lRyAttQ0UeeD0GIdvKn23eLbLDM23Wlh21pw1iL5Az5XzR7YKv0nQwzSi7vAazoPdxCXvCP9iRzHgSicqbdBfHBvsLFdAffc0WGtLFTs59UTVHKAu8eTW68zpfmUkHla2+zL4dAelwQrvY/BuBiZHRCl3Uzt4756e3GGWeaR9F7bxKg91fpwa+wxRx+4kkvpqgNYZB6Wvs7PFVixbzZhAb+nwf5J4jAEV6gxVbj3I5hug==',
2044 game['fn'].loadSettings();
2045 game['fn'].applySettings();
2047 if(game.ui.root.querySelectorAll('.ui-page.credits .area h3').length > 3) {
2048 // If the credits have more than three third-level headers, that means we are
2049 // in the freeware version and can make the CSS adjustments it needs.
2050 let css = document.styleSheets[0];
2051 css.insertRule('.upInTheAirGame .ui-page.credits .person { position: relative; height: 4em; padding-left: calc(4em + 1ex); display: flex; flex-direction: column; justify-content: center; }');
2052 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; }');
2053 game.ui.root.querySelectorAll('.ui-page.credits .area .person').forEach((person) => {
2054 let personName = Array.from(person.classList).filter(c => c != 'person')[0];
2055 let imageFormat = (personName == 'nina') ? 'png' : 'jpg';
2056 css.insertRule('.upInTheAirGame .ui-page.credits .person.' + personName + '::before { background-image: url("' + game['deploymentOptions']['assetUrlPrefix'] + 'textures/person-' + personName + '.' + imageFormat + '"); }');
2060 game.ui.root.querySelectorAll('button.goto').forEach((btn) => {
2061 btn.addEventListener('click', (e) => {
2062 if(game.view && !game.view.music) {
2063 game.view.audioListener = new THREE.AudioListener();
2064 game.view.camera.add(game.view.audioListener);
2065 game.view.music = new THREE.Audio(game.view.audioListener);
2066 game.view.music.setBuffer(game.assets['audio']['music-' + game.settings['audio']['theme']]);
2067 game.view.music.setVolume(game.settings['audio']['music']);
2068 game.view.windSound = new THREE.Audio(game.view.audioListener);
2069 game.view.windSound.setBuffer(game.assets['audio']['wind']);
2070 game.view.windSound.setVolume(game.settings['audio']['sounds']);
2071 game.view.windSound.setLoop(false);
2073 let btn = e.target.closest('button');
2074 let target = Array.from(btn.classList).filter(c => c != 'goto')[0];
2075 if(target == 'previous') {
2076 target = game.ui.previousPage;
2078 game['fn'].moveToPage(target);
2082 game.ui.root.querySelectorAll('.options .controls input, .options .graphics input, .options .hud input, .options .feather input, .options .accessibility input, .options .accessibility select').forEach((elem) => {
2083 elem.addEventListener('change', () => {
2084 game['fn'].applySettings();
2085 if(elem.name == 'upInTheAirGame-controls') {
2086 game.ui.root.querySelector('.controls .leftside').style.display = (['touchpad', 'thumbstick'].includes(game.settings['controls'])) ? 'block' : 'none';
2087 game.ui.root.querySelectorAll('.options .controls p span:not(.' + game.settings['controls'] + ')').forEach(span => span.style.display = 'none');
2088 game.ui.root.querySelector('.options .controls span.' + game.settings['controls']).style.display = 'block';
2089 } else if(elem.value == 'highcontrast' || elem.name == 'upInTheAirGame-graphics') {
2090 game['fn'].createMeshes();
2091 } else if(elem.name == 'upInTheAirGame-feather') {
2092 game['fn'].createFeather();
2097 game.ui.root.querySelector('.ui-page.title .system-buttons input').addEventListener('change', (e) => {
2098 game.view.muted = e.target.checked;
2101 game.ui.root.querySelector('.ui-page.title .system-buttons button').addEventListener('click', (e) => {
2102 if(document.fullscreenElement == game.ui.root.parentNode) {
2103 document.exitFullscreen();
2105 game.ui.root.parentNode.requestFullscreen();
2109 game.ui.root.querySelectorAll('.ui-page .audio input[type=range]').forEach((elem) => {
2110 elem.addEventListener('input', (e) => {
2111 let audioCategory = Array.from(e.target.classList).filter(v => ['music', 'sounds'].includes(v))[0];
2112 game.ui.root.querySelector('.ui-page.options .audio input[type=range].' + audioCategory).value = e.target.value;
2113 game['fn'].applySettings();
2117 game.ui.root.querySelectorAll('.options .audio button').forEach((btn) => {
2118 btn.addEventListener('click', (e) => {
2119 if(e.target.classList.contains('music')) {
2120 if(game.view.music.isPlaying) {
2121 game.view.music.stop();
2122 if(game.view.music.timeoutID) {
2123 clearTimeout(game.view.music.timeoutID);
2124 delete game.view.music.timeoutID;
2127 game.view.music.offset = 36;
2128 if(!game.view.muted) {
2129 game.view.music.play();
2131 game.view.music.timeoutID = setTimeout(() => {
2132 game.view.music.stop();
2135 } else if(e.target.classList.contains('sounds')) {
2136 game['fn'].playRandomSound();
2141 game.ui.root.querySelectorAll('.options .keyboard label button').forEach((btn) => {
2142 btn.addEventListener('click', () => {
2143 if(game.ui.root.querySelector('.ui-page.keyboard-modal')) {
2146 const keyboardModal = document.createElement('div');
2147 keyboardModal.classList.add('ui-page', 'keyboard-modal');
2148 const instruction = document.createElement('span');
2149 const direction = btn.classList[0];
2150 keyboardModal.classList.add(direction);
2151 instruction.innerText = 'Please press the key for “' + direction[0].toUpperCase() + direction.slice(1) + '”';
2152 keyboardModal.appendChild(instruction);
2153 game.ui.root.appendChild(keyboardModal);
2157 game.ui.root.querySelector('.options .keyboard button[value="reset"]').addEventListener('click', (e) => {
2158 const container = e.target.parentNode;
2159 container.querySelector('button.up').value = 'ArrowUp|w';
2160 container.querySelector('button.right').value = 'ArrowRight|d';
2161 container.querySelector('button.down').value = 'ArrowDown|s';
2162 container.querySelector('button.left').value = 'ArrowLeft|a';
2163 game['fn'].applySettings();
2164 game['fn'].loadSettings();
2167 game.ui.root.querySelectorAll('.ui-page .areatabs button').forEach((btn) => {
2168 btn.addEventListener('click', (e) => {
2169 btn.parentNode.querySelectorAll('button').forEach((otherBtn) => {
2170 otherBtn.classList.remove('active');
2171 let val = otherBtn.classList[0];
2172 otherBtn.closest('.ui-page').querySelector('div.' + val).style.display = 'none';
2174 btn.classList.add('active');
2175 let val = Array.from(btn.classList).filter(c => c != 'active')[0];
2176 btn.closest('.ui-page').querySelector('div.' + val).style.display = 'flex';
2180 game.ui.root.style.fontSize = (game.ui.root.clientWidth / 48) + 'px';
2181 window.addEventListener('resize', () => {
2182 game.ui.root.style.fontSize = (game.ui.root.clientWidth / 48) + 'px';
2185 window.addEventListener('scroll', () => {
2186 if(!['gameplay', 'openingcutscene', 'endingcutscene'].includes(game.ui.currentPage)) {
2189 let bbox = game.ui.root.querySelector('canvas').getBoundingClientRect();
2190 if(bbox.bottom < -100 || bbox.top - bbox.height > 100 || bbox.left + bbox.width < -100 || bbox.left - window.innerWidth > 100) {
2191 game['fn'].moveToPage('pause', true);
2194 window.addEventListener('blur', () => {
2195 if(['gameplay', 'openingcutscene', 'endingcutscene'].includes(game.ui.currentPage)) {
2196 game['fn'].moveToPage('pause', true);
2200 document.addEventListener('keydown', (e) => {
2201 const keyboardModal = game.ui.root.querySelector('.keyboard-modal');
2203 const direction = [...keyboardModal.classList].filter(c => c != 'ui-page' && c != 'keyboard-modal')[0];
2204 if(e.key != 'Escape') {
2205 game.ui.root.querySelector('.options .keyboard label button.' + direction).value = e.key;
2206 game['fn'].applySettings();
2207 game['fn'].loadSettings();
2209 keyboardModal.remove();
2211 e.stopPropagation();
2214 if(game.ui.currentPage == 'title' && e.key.match(/[a-z]/)) {
2215 game.view.cheatBuffer = (game.view.cheatBuffer + e.key).slice(-25);
2216 for(let len = 10; len <= 25; len++) {
2217 if(game.view.cheatBuffer.length < len) {
2220 let unlock = game['fn'].unlockWithKey(game.view.cheatBuffer.slice(-len));
2221 if(unlock && unlock['type'] == 'feather' && !game.settings['unlocks'].includes(unlock['name'])) {
2222 game['fn'].playRandomSound();
2223 game['fn'].unlockFeather(unlock['name'], unlock['url']);
2224 game['fn'].moveToPage('unlock');
2226 else if(unlock && unlock['type'] == 'custom') {
2227 if(!game.var.sessionUnlocks) {
2228 game.var.sessionUnlocks = [];
2230 if(!game.var.sessionUnlocks.includes(unlock['name'])) {
2231 game['fn'].playRandomSound();
2232 let action = new Function(unlock['action']);
2233 action.call(null, game, THREE);
2234 game.var.sessionUnlocks.push(unlock['name']);
2240 if(e.key == 'Escape') {
2241 if(['gameplay', 'openingcutscene', 'endingcutscene'].includes(game.ui.currentPage)) {
2242 game['fn'].moveToPage('pause', true);
2243 } else if(game.ui.currentPage == 'pause') {
2244 game['fn'].moveToPage(game.ui.previousPage, true);
2249 window.addEventListener('gamepadconnected', (e) => {
2250 game.ui.gamepads.push(e.gamepad);
2252 window.addEventListener('gamepaddisconnected', (e) => {
2253 if(game.ui.gamepads.includes(e.gamepad)) {
2254 game.ui.gamepads.splice(game.ui.gamepads.indexOf(e.gamepad), 1);
2258 game.ui.root.querySelector('.ui-page.pause button.title').addEventListener('click', () => {
2262 game['fn'].loadAllAssets((progress) => {
2263 let percentage = Math.floor(100 * progress);
2264 game.ui.root.querySelector('.ui-page.loading progress').value = percentage;
2265 game.ui.root.querySelector('.ui-page.loading span').innerText = percentage;
2267 if(window.location.hostname == 'fietkau.media' && window.location.pathname == '/up_in_the_air') {
2268 game.ui.root.querySelector('.ui-page.title .footer span:last-child').remove();
2270 let controlsInterstitial = false;
2271 if(!game.settings['controls']) {
2272 controlsInterstitial = true;
2274 if(matchMedia('(hover: hover)').matches) {
2277 control = 'touchpad';
2279 game.ui.root.querySelector('.controls input[value="' + control + '"]').checked = true;
2280 game['fn'].applySettings();
2281 game['fn'].loadSettings();
2282 game.ui.root.querySelectorAll('.ui-page.controls .' + ((control == 'mouse') ? 'touchpad' : 'mouse')).forEach(elem => elem.remove());
2284 if(!game.assets.audiothemes.includes(game.settings['audio']['theme'])) {
2285 game.settings['audio']['theme'] = game.assets.audiothemes[0];
2287 if(game.assets.audiothemes.length == 1) {
2288 game.ui.root.querySelector('.ui-page.options .audiotheme').style.display = 'none';
2290 let container = game.ui.root.querySelector('.ui-page.options .audiotheme');
2291 for(let audioTheme of game.assets.audiothemes) {
2292 let snippet = container.children[0].content.cloneNode(true).children[0];
2293 snippet.children[0].value = audioTheme;
2294 if(audioTheme == game.settings['audio']['theme']) {
2295 snippet.children[0].checked = true;
2297 snippet.children[0].addEventListener('change', () => {
2298 game['fn'].applySettings();
2299 game.view.music.setBuffer(game.assets['audio']['music-' + game.settings['audio']['theme']]);
2301 snippet.childNodes[1].textContent = ' ' + audioTheme[0].toUpperCase() + audioTheme.slice(1);
2302 container.appendChild(snippet);
2304 if(controlsInterstitial) {
2305 game['fn'].moveToPage('controls');
2307 game['fn'].moveToPage('title');
2315 // Set up name mirrors for each function that should survive most minifiers and transpilers
2316 game['fn'].animate['friendlyName'] = 'animate';
2317 game['fn'].applyForceToFeather['friendlyName'] = 'applyForceToFeather';
2318 game['fn'].applySettings['friendlyName'] = 'applySettings';
2319 game['fn'].createFeather['friendlyName'] = 'createFeather';
2320 game['fn'].createMeshes['friendlyName'] = 'createMeshes';
2321 game['fn'].easeInOut['friendlyName'] = 'easeInOut';
2322 game['fn'].initializeGame['friendlyName'] = 'initializeGame';
2323 game['fn'].lerp['friendlyName'] = 'lerp';
2324 game['fn'].loadAllAssets['friendlyName'] = 'loadAllAssets';
2325 game['fn'].loadSettings['friendlyName'] = 'loadSettings';
2326 game['fn'].moveToPage['friendlyName'] = 'moveToPage';
2327 game['fn'].playRandomSound['friendlyName'] = 'playRandomSound';
2328 game['fn'].prepareWordMesh['friendlyName'] = 'prepareWordMesh';
2329 game['fn'].reset['friendlyName'] = 'reset';
2330 game['fn'].start['friendlyName'] = 'start';
2331 game['fn'].unlockFeather['friendlyName'] = 'unlockFeather';
2332 game['fn'].unlockWithKey['friendlyName'] = 'unlockWithKey';