Up-in-the-Air – commitdiff

You can use Git to clone the repository via the web URL. Download snapshot (zip)
Feather selection fully working
authorJulian Fietkau <git@fietkau.software>
Thu, 26 Sep 2024 00:38:07 +0000 (02:38 +0200)
committerJulian Fietkau <git@fietkau.software>
Thu, 26 Sep 2024 00:38:07 +0000 (02:38 +0200)
index.html
main.js

index 7c1b1a0d543c1dd11eb18802e88dfd6ae18241b0..3d811f3daeb59de4109c9246cbf8ecd1816fcb90 100644 (file)
 <label><input type="radio" name="upInTheAirGame-feather" value="green"><img src="textures/feather-green.png" alt="Green feather"></label>
 <label><input type="radio" name="upInTheAirGame-feather" value="black"><img src="textures/feather-black.png" alt="Black feather"></label>
 <label><input type="radio" name="upInTheAirGame-feather" value="brown"><img src="textures/feather-brown.png" alt="Brown feather"></label>
-<label><input type="radio" name="upInTheAirGame-feather" value="brown"><img src="textures/feather-orange.png" alt="Orange feather"></label>
-<label><input type="radio" name="upInTheAirGame-feather" value="brown"><img src="textures/feather-purple.png" alt="Purple feather"></label>
+<label><input type="radio" name="upInTheAirGame-feather" value="orange"><img src="textures/feather-orange.png" alt="Orange feather"></label>
+<label><input type="radio" name="upInTheAirGame-feather" value="purple"><img src="textures/feather-purple.png" alt="Purple feather"></label>
 </div>
 </div>
 </div>
diff --git a/main.js b/main.js
index aafcd25de81912044fd48efffdb0b7814ad496e7..c4b9f80738892f532fe53363e9469393d0ba3d42 100644 (file)
--- a/main.js
+++ b/main.js
@@ -74,8 +74,6 @@ function loadAllAssets(game, renderProgressCallback) {
       'textures/feather-black.png': 1026,
       'textures/feather-blue.png': 1026,
       'textures/feather-brown.png': 1027,
-      'textures/feather-ghost.png': 1023,
-      'textures/feather-golden.png': 1027,
       'textures/feather-green.png': 1028,
       'textures/feather-orange.png': 1028,
       'textures/feather-purple.png': 1028,
@@ -86,6 +84,15 @@ function loadAllAssets(game, renderProgressCallback) {
       'textures/windowsill1.png': 483119,
       'textures/windowsill2.png': 484665,
     };
+    for(let unlockable of ['golden', 'ghost']) {
+      if(game.settings['unlocks'].includes(unlockable)) {
+        if(unlockable == 'golden') {
+          todoList['textures/feather-' + unlockable + '.png'] = 1027;
+        } else {
+          todoList['textures/feather-' + unlockable + '.png'] = 1023;
+        }
+      }
+    }
     let total = Object.keys(todoList).map(k => todoList[k]).reduce((a, b) => a + b, 0);
     let progress = {};
     const loader = {
@@ -106,7 +113,10 @@ function loadAllAssets(game, renderProgressCallback) {
         if(segments[0] == 'textures') {
           result.colorSpace = THREE.SRGBColorSpace;
           result.magFilter = THREE.NearestFilter;
-          if(segments[1].split('.')[0] == 'highcontrast-backdrop') {
+          if(segments[1].split('.')[0].startsWith('feather-')) {
+            result.repeat = new THREE.Vector2(1, -1);
+            result.wrapT = THREE.RepeatWrapping;
+          } else if(segments[1].split('.')[0] == 'highcontrast-backdrop') {
             result.repeat = new THREE.Vector2(25, 25);
             result.wrapS = THREE.RepeatWrapping;
             result.wrapT = THREE.RepeatWrapping;
@@ -175,22 +185,6 @@ function init(game, canvas) {
     return deltaTime;
   };
 
-  const featherGeometry = new THREE.PlaneGeometry(1.6, 0.5);
-  const featherMaterial = new THREE.MeshPhongMaterial({
-    map: game.assets.textures.feather,
-    transparent: true,
-    alphaTest: 0.5,
-    side: THREE.DoubleSide,
-  });
-  game.objects.feather = new THREE.Mesh(featherGeometry, featherMaterial);
-  game.objects.feather.rotation.order = 'ZXY';
-  game.objects.feather.position.set(0, -game.courseRadius, 0);
-  scene.add(game.objects.feather);
-  game.objects.feather.speed = new THREE.Vector3(0, 0, 0);
-  game.gravity = new THREE.Vector3(0, -0.1, 0);
-  game.objects.feather.swayDirection = 0.2;
-  game.objects.feather.twistSpeed = 0.1;
-
   const pinwheelGeometry = new THREE.BoxGeometry(.9, .9, 0.01);
   const pinwheelMaterial = new THREE.MeshPhongMaterial({
     map: game.assets.textures.pinwheel,
@@ -227,6 +221,7 @@ function init(game, canvas) {
   game.view.scene = scene;
 
   createMeshes(game);
+  createFeather(game);
   reset(game);
 
   function pinwheelPositionUpdate(game, viewportX, viewportY) {
@@ -864,6 +859,39 @@ function applySettings(game) {
   }
 }
 
+function createFeather(game) {
+  let position, rotation;
+  if(game.objects.feather) {
+    position = game.objects.feather.position;
+    rotation = game.objects.feather.rotation;
+    game.objects.feather.geometry.dispose();
+    game.objects.feather.material.dispose();
+    game.view.scene.remove(game.objects.feather);
+    delete game.objects.feather;
+  }
+
+  const featherGeometry = new THREE.PlaneGeometry(1.6, 0.5);
+  game.view.materials.feather = new THREE.MeshPhongMaterial({
+    map: game.assets.textures['feather-' + game.settings['feather']],
+    transparent: true,
+    alphaTest: 0.5,
+    side: THREE.DoubleSide,
+  });
+  game.objects.feather = new THREE.Mesh(featherGeometry, game.view.materials.feather);
+  game.objects.feather.rotation.order = 'ZXY';
+  if(position) {
+    game.objects.feather.position.set(position.x, position.y, position.z);
+  }
+  if(rotation) {
+    game.objects.feather.rotation.set(rotation.x, rotation.y, rotation.z);
+  }
+  game.view.scene.add(game.objects.feather);
+  game.objects.feather.speed = new THREE.Vector3(0, 0, 0);
+  game.gravity = new THREE.Vector3(0, -0.1, 0);
+  game.objects.feather.swayDirection = 0.2;
+  game.objects.feather.twistSpeed = 0.1;
+}
+
 function createMeshes(game) {
   if(game.objects.clouds && game.objects.clouds.parent == game.view.scene) {
     game.view.scene.remove(game.objects.clouds);
@@ -896,7 +924,14 @@ function createMeshes(game) {
     delete game.view.materials;
   }
 
-  game.view.materials = {};
+  if(game.view.materials && game.view.materials.feather) {
+    game.view.materials = {
+      'feather': game.view.materials['feather'],
+    };
+  } else {
+    game.view.materials = {};
+  }
+
   if(!game.settings['highcontrast']) {
     let cloudShaders;
     let cloudGeometry = new THREE.PlaneGeometry(1, 200 / 350);
@@ -1134,9 +1169,10 @@ game.ui.root.querySelectorAll('.options .controls input, .options .graphics inpu
     if(elem.name == 'upInTheAirGame-controls') {
       game.ui.root.querySelectorAll('.options .controls p span:not(.' + game.settings['controls'] + ')').forEach(span => span.style.display = 'none');
       game.ui.root.querySelector('.options .controls span.' + game.settings['controls']).style.display = 'block';
-    }
-    if(elem.value == 'highcontrast' || elem.name == 'upInTheAirGame-graphics') {
+    } else if(elem.value == 'highcontrast' || elem.name == 'upInTheAirGame-graphics') {
       createMeshes(game);
+    } else if(elem.name == 'upInTheAirGame-feather') {
+      createFeather(game);
     }
   });
 });