reenabled diagonal movement
authorkharhamel <oognic@gmail.com>
Thu, 30 Apr 2020 17:36:28 +0000 (19:36 +0200)
committerkharhamel <oognic@gmail.com>
Thu, 30 Apr 2020 17:36:28 +0000 (19:36 +0200)
front/src/Enum/EnvironmentVariable.ts
front/src/Phaser/Entity/PlayableCaracter.ts
front/src/Phaser/Player/Player.ts

index 6c0226a287166ad4dc05f30f5c2d7f5870950b95..f44f717b326994f13696de5de747a25db1159fab 100644 (file)
@@ -1,4 +1,4 @@
-const DEBUG_MODE: boolean = !!process.env.DEBUG_MODE || false;
+const DEBUG_MODE: boolean = process.env.DEBUG_MODE as any === true;
 const API_URL = process.env.API_URL || "http://api.workadventure.localhost";
 const ROOM = [process.env.ROOM || "THECODINGMACHINE"];
 const RESOLUTION = 4;
index b84d2dd83ad80ce2c6e3d22df60e9f3691c92a2c..987d6bd373daac6dc4bda81a743ef936e59037c1 100644 (file)
@@ -22,18 +22,15 @@ export class PlayableCaracter extends Phaser.Physics.Arcade.Sprite {
 
         this.setVelocity(x, y);
 
-        //todo improve animations to better account for diagonal movement
-        if (this.body.velocity.x > 0) { //moving right
-            this.play(PlayerAnimationNames.WalkRight, true);
-        }
-        if (this.body.velocity.x < 0) { //moving left
-            this.anims.playReverse(PlayerAnimationNames.WalkLeft, true);
-        }
+        //up or down animationss are prioritized over left and right
         if (this.body.velocity.y < 0) { //moving up
             this.play(PlayerAnimationNames.WalkUp, true);
-        }
-        if (this.body.velocity.y > 0) { //moving down
+        } else if (this.body.velocity.y > 0) { //moving down
             this.play(PlayerAnimationNames.WalkDown, true);
+        } else if (this.body.velocity.x > 0) { //moving right
+            this.play(PlayerAnimationNames.WalkRight, true);
+        } else if (this.body.velocity.x < 0) { //moving left
+            this.anims.playReverse(PlayerAnimationNames.WalkLeft, true);
         }
 
         if(this.bubble) {
index a7798720170b8992bcd1fd118984ad9790aff130..60326a2721898c104651f4c88fc7a788220cb916 100644 (file)
@@ -66,27 +66,25 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
         let speedMultiplier = activeEvents.get(UserInputEvent.SpeedUp) ? 25 : 9;
         let moveAmount = speedMultiplier * delta;
 
+        let x = 0;
+        let y = 0;
         if (activeEvents.get(UserInputEvent.MoveUp)) {
-            this.move(0, -moveAmount);
-            haveMove = true;
+            y = - moveAmount;
             direction = PlayerAnimationNames.WalkUp;
+        } else if (activeEvents.get(UserInputEvent.MoveDown)) {
+            y = moveAmount;
+            direction = PlayerAnimationNames.WalkDown;
         }
         if (activeEvents.get(UserInputEvent.MoveLeft)) {
-            this.move(-moveAmount, 0);
-            haveMove = true;
+            x = -moveAmount;
             direction = PlayerAnimationNames.WalkLeft;
-        }
-        if (activeEvents.get(UserInputEvent.MoveDown)) {
-            this.move(0, moveAmount);
-            haveMove = true;
-            direction = PlayerAnimationNames.WalkDown;
-        }
-        if (activeEvents.get(UserInputEvent.MoveRight)) {
-            this.move(moveAmount, 0);
-            haveMove = true;
+        } else if (activeEvents.get(UserInputEvent.MoveRight)) {
+            x = moveAmount;
             direction = PlayerAnimationNames.WalkRight;
         }
-        if (!haveMove) {
+        if (x !== 0 || y !== 0) {
+            this.move(x, y);
+        } else {
             direction = PlayerAnimationNames.None;
             this.stop();
         }