fixed the player animations
authorkharhamel <oognic@gmail.com>
Sun, 12 Apr 2020 16:28:05 +0000 (18:28 +0200)
committerkharhamel <oognic@gmail.com>
Sun, 12 Apr 2020 16:28:05 +0000 (18:28 +0200)
front/src/Phaser/Game/GameScene.ts
front/src/Phaser/NonPlayer/NonPlayer.ts
front/src/Phaser/Player/Player.ts

index dac1f2fc10c61780776aa94a28819960710522e4..648e6579664e35bff318fa6a124ea279dc9fc2ef 100644 (file)
@@ -6,7 +6,7 @@ import {NonPlayer} from "../NonPlayer/NonPlayer";
 
 export enum Textures {
     Rock = 'rock',
-    Player = 'player',
+    Player = 'playerModel',
     Map = 'map',
     Tiles = 'tiles'
 }
@@ -39,7 +39,11 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
             'resources/characters/pipoya/Male 01-1.png',
             { frameWidth: 32, frameHeight: 32 }
         );
+    }
 
+    //hook create scene
+    create(): void {
+        //anims cannot be in preload because it needs to wait to the sprit to be loaded
         getPlayerAnimations().forEach(d => {
             this.anims.create({
                 key: d.key,
@@ -48,10 +52,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
                 //repeat: d.repeat
             });
         });
-    }
-
-    //hook create scene
-    create(): void {
+        
         this.userInputManager = new UserInputManager(this);
 
         //create entities
@@ -68,8 +69,8 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
         //create map
         let currentMap = this.add.tilemap(Textures.Map);
         let terrain = currentMap.addTilesetImage(Textures.Tiles, "tiles");
-        let bottomLayer = currentMap.createStaticLayer("Calque 1", [terrain], 0, 0).setDepth(-1);
-        let topLayer =  currentMap.createStaticLayer("Calque 2", [terrain], 0, 0);
+        let bottomLayer = currentMap.createStaticLayer("Calque 1", [terrain], 0, 0).setDepth(-2);
+        let topLayer =  currentMap.createStaticLayer("Calque 2", [terrain], 0, 0).setDepth(-1);
         this.physics.world.setBounds(0,0, currentMap.widthInPixels, currentMap.heightInPixels);
         
         this.physics.add.collider(this.player, topLayer);
@@ -105,6 +106,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
         this.player.move(eventList);
         
         this.otherPlayers.getChildren().forEach((otherPlayer: NonPlayer) => {
+            //this.physics.accelerateToObject(otherPlayer, this.player); //this line make the models chase the player
             otherPlayer.setVelocity(20, 5);
         })
     }
index d9b22001866f881c45b509f42fa2a1e8c3225cdc..46fa645083c62db188a546cd926497c39ee6345e 100644 (file)
@@ -4,7 +4,7 @@ import {Textures} from "../Game/GameScene";
 export class NonPlayer extends PlayableCaracter {
     
     constructor(scene: Phaser.Scene, x: number, y: number) {
-        super(scene, x, y, Textures.Player, 26);
+        super(scene, x, y, Textures.Player, 1);
         this.setSize(32, 32); //edit the hitbox to better match the caracter model
     }
 }
\ No newline at end of file
index e4395b3de5c69bfebacb24794a5e65b9c5ba293b..ff2278f5b19c83ab5ec06c3c67992b4d8fc57a4c 100644 (file)
@@ -7,7 +7,7 @@ import {PlayableCaracter} from "../Entity/PlayableCaracter";
 export class Player extends PlayableCaracter{
     
     constructor(scene: Phaser.Scene, x: number, y: number) {
-        super(scene, x, y, Textures.Player, 26);
+        super(scene, x, y, Textures.Player, 1);
         this.setImmovable(false); //the current player model should be push away by other players to prevent conflict
         this.setSize(32, 32); //edit the hitbox to better match the caracter model
     }
@@ -19,27 +19,28 @@ export class Player extends PlayableCaracter{
 
         if(activeEvents.get(UserInputEvent.MoveUp)){
             this.setVelocity(0, -speed)
-            playAnimation(this, PlayerAnimationNames.WalkUp);
         } else if(activeEvents.get(UserInputEvent.MoveLeft)){
             this.setVelocity(-speed, 0)
         } else if(activeEvents.get(UserInputEvent.MoveDown)){
-            playAnimation(this, PlayerAnimationNames.WalkDown);
             this.setVelocity(0, speed)
         } else if(activeEvents.get(UserInputEvent.MoveRight)){
             this.setVelocity(speed, 0)
         } else {
             this.setVelocity(0, 0)
-            playAnimation(this, PlayerAnimationNames.None);
+        }
+
+        if (this.body.velocity.x > 0) { //moving right
+            this.play("right", true);
+        } else if (this.body.velocity.x < 0) { //moving left
+            this.anims.playReverse("left", true);
+        } else if (this.body.velocity.y < 0) { //moving up
+            this.play("up", true);
+        } else if (this.body.velocity.y > 0) { //moving down
+            this.play("down", true);
         }
     }
 
     stop() {
         this.setVelocity(0, 0)
     }
-
-    /*private sharePosition(direction : string){
-        if(ConnexionInstance) {
-            ConnexionInstance.sharePosition((this.scene as GameSceneInterface).RoomId, this.x, this.y, direction);
-        }
-    }*/
 }
\ No newline at end of file