TA159

Notas, resueltos y trabajos practicos de la materia Sistemas Gráficos
Index Commits Files Refs Submodules README LICENSE
commit e3d257f95c7e7e6bdfa0430e1776c4f7b6335dd7
parent 54f36df6fbd8cf04ef503e1a4ece0f6951aeeac0
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date:   Sat,  6 Jul 2024 12:50:37 -0300

add 'running' like behaviour by pressing `Shift+w`

Diffstat:
Mtp/src/scene.js | 29++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/tp/src/scene.js b/tp/src/scene.js
@@ -36,6 +36,7 @@ let settings = {
 let raycaster;
 
 let moveForward = false;
+let moveForwardRunning = false;
 let moveBackward = false;
 let moveLeft = false;
 let moveRight = false;
@@ -156,6 +157,9 @@ function keyHandler(event) {
             case 'ArrowUp':
             case 'KeyW':
                 moveForward = true;
+                if(event.shiftKey) {
+                    moveForwardRunning = true;
+                }
                 break;
             case 'ArrowLeft':
             case 'KeyA':
@@ -190,12 +194,22 @@ function keyHandler(event) {
                 }
                 break;
         }
+        switch(event.key) {
+            case "Shift":
+                if(!moveForwardRunning) {
+                    moveForwardRunning = true;
+                }
+                break;
+            default:
+                break;
+        }                
     } else {
         // key up
         switch (event.code) {
             case 'ArrowUp':
             case 'KeyW':
                 moveForward = false;
+                moveForwardRunning = false;
                 break;
             case 'ArrowLeft':
             case 'KeyA':
@@ -210,6 +224,15 @@ function keyHandler(event) {
                 moveRight = false;
                 break;
         }
+        switch(event.key) {
+            case "Shift":
+                if(moveForwardRunning) {
+                    moveForwardRunning = false;
+                }
+                break;
+            default:
+                break;
+        }
     }
 }
 
@@ -616,7 +639,11 @@ function mainLoop() {
         direction.normalize(); // this ensures consistent movements in all directions
 
         if (moveForward || moveBackward) {
-            velocity.z -= direction.z * 100.0 * delta;
+            if(moveForwardRunning) {
+                velocity.z -= direction.z * 200.0 * delta;
+            } else {
+                velocity.z -= direction.z * 100.0 * delta;
+            }
         }
 
         if (moveLeft || moveRight) {