Up-in-the-Air – commitdiff

You can use Git to clone the repository via the web URL. Download snapshot (zip)
Refactor word and letter positioning to use the native position of words more
authorJulian Fietkau <git@fietkau.software>
Tue, 24 Sep 2024 19:20:50 +0000 (21:20 +0200)
committerJulian Fietkau <git@fietkau.software>
Tue, 24 Sep 2024 19:20:50 +0000 (21:20 +0200)
main.js

diff --git a/main.js b/main.js
index ec38356cd22faa3420035db7aa30e7bb1ea0b076..fadccfe68c6d16b1bb05cd0582748b76146f6855 100644 (file)
--- a/main.js
+++ b/main.js
@@ -223,7 +223,6 @@ function init(game, canvas) {
   game.var.pinwheelDistance = new THREE.Vector3();
   game.var.notCollectedPos = new THREE.Vector3();
   game.var.collectedPos = new THREE.Vector3();
-  game.var.letterPos = new THREE.Vector3();
   renderer.setAnimationLoop(() => { animate(game, renderer, scene); });
 }
 
@@ -305,14 +304,10 @@ function reset(game) {
       let randomPlacementAngle = Math.random() * 2 * Math.PI;
       let randomPlacementX = Math.sin(randomPlacementAngle) * randomPlacementRadius;
       let randomPlacementY = Math.cos(randomPlacementAngle) * randomPlacementRadius;
-      word.mapPos = new THREE.Vector3(
-        randomCameraX + randomPlacementX,
-        randomCameraY + randomPlacementY,
-        0,
-      );
+      word.position.set(randomCameraX + randomPlacementX, randomCameraY + randomPlacementY, 0);
       placementSuccess = true;
       for(let j = 0; j < i; j++) {
-        if(interWordDistance.subVectors(word.mapPos, game.objects.words[j].mapPos).length() <= 1.2) {
+        if(interWordDistance.subVectors(word.position, game.objects.words[j].position).length() <= 1.2) {
           placementSuccess = false;
           break;
         }
@@ -523,7 +518,7 @@ function animate(game, renderer, scene) {
     let word = game.objects.words[i];
     if(!word.collected &&
        game.objects.feather.speed.length() < 10.0 &&
-       new THREE.Vector3().subVectors(word.mapPos, game.objects.feather.position).length() < collectingRadius) {
+       new THREE.Vector3().subVectors(word.position, game.objects.feather.position).length() < collectingRadius) {
       word.collected = game.view.clock.getElapsedTime();
       game.objects.words.collectedCount += 1;
     }
@@ -537,8 +532,8 @@ function animate(game, renderer, scene) {
       let animationProgress = (((game.timeProgress + 5 * word.randomAnimOffset) % 5) / 5 + j / 37) % 1;
       if(!word.collected || game.view.clock.getElapsedTime() - word.collected <= collectionAnimationDuration) {
         const wordAnimationRadius = 0.2;
-        x = word.mapPos.x + wordAnimationRadius * Math.cos(animationProgress * 5 * Math.PI * 2);
-        y = word.mapPos.y + wordAnimationRadius * Math.sin(animationProgress * 4 * Math.PI * 2);
+        x = word.position.x + wordAnimationRadius * Math.cos(animationProgress * 5 * Math.PI * 2);
+        y = word.position.y + wordAnimationRadius * Math.sin(animationProgress * 4 * Math.PI * 2);
         z = wordAnimationRadius * Math.sin(animationProgress * 6 * Math.PI * 2);
         game.var.notCollectedPos.set(x, y, z);
       }
@@ -555,15 +550,15 @@ function animate(game, renderer, scene) {
       }
       if(game.var.notCollectedPos.length() > 0 && game.var.collectedPos.length() > 0) {
         let collectingProgress = easeInOut(Math.max(0.0, Math.min(1.0, (game.view.clock.getElapsedTime() - word.collected) / collectionAnimationDuration)));
-        game.var.letterPos.lerpVectors(game.var.notCollectedPos, game.var.collectedPos, collectingProgress);
+        letter.position.lerpVectors(game.var.notCollectedPos, game.var.collectedPos, collectingProgress);
         let scale = lerp(1.0, collectedScale, collectingProgress);
         letter.scale.set(scale, scale, scale);
       } else if(game.var.notCollectedPos.length() > 0) {
-        game.var.letterPos.set(game.var.notCollectedPos.x, game.var.notCollectedPos.y, game.var.notCollectedPos.z);
+        letter.position.set(game.var.notCollectedPos.x, game.var.notCollectedPos.y, game.var.notCollectedPos.z);
       } else if(game.var.collectedPos.length() > 0) {
-        game.var.letterPos.set(game.var.collectedPos.x, game.var.collectedPos.y, game.var.collectedPos.z);
+        letter.position.set(game.var.collectedPos.x, game.var.collectedPos.y, game.var.collectedPos.z);
       }
-      letter.position.set(game.var.letterPos.x, game.var.letterPos.y, game.var.letterPos.z);
+      letter.position.sub(word.position);
       let rotation = (game.timeProgress * 3) % (2 * Math.PI);
       letter.rotation.set(rotation + j, rotation + 2*j, rotation + 3*j);
     }