Merge branch 'interaction' into kharhamel-interaction
authorgparant <g.parant@thecodingmachine.com>
Mon, 13 Apr 2020 11:42:21 +0000 (13:42 +0200)
committergparant <g.parant@thecodingmachine.com>
Mon, 13 Apr 2020 11:42:21 +0000 (13:42 +0200)
# Conflicts:
# front/src/Phaser/Game/CameraManager.ts
# front/src/Phaser/Game/GameScene.ts
# front/src/Phaser/Game/MapManager.ts
# front/src/Phaser/Player/Player.ts

1  2 
front/src/Phaser/Entity/PlayableCaracter.ts
front/src/Phaser/Game/GameManager.ts
front/src/Phaser/Game/GameScene.ts
front/src/Phaser/Game/MapManager.ts
front/src/Phaser/NonPlayer/NonPlayer.ts
front/src/Phaser/Player/Animation.ts
front/src/Phaser/Player/Player.ts
front/src/Phaser/UserInput/UserInputManager.ts
front/src/index.ts

index 0000000000000000000000000000000000000000,0c9db376038d079a6331d8b4fa2c8bf91a7a4dda..69bcfd55728f20449c2d2171228bf8656c167fba
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,44 +1,45 @@@
 -        scene.sys.updateList.add(this);
 -        scene.sys.displayList.add(this);
+ import {getPlayerAnimations, playAnimation, PlayerAnimationNames} from "../Player/Animation";
+ import {ActiveEventList, UserInputEvent} from "../UserInput/UserInputManager";
+ import {SpeechBubble} from "./SpeechBubble";
+ export class PlayableCaracter extends Phaser.Physics.Arcade.Sprite {
+     private bubble: SpeechBubble;
+     constructor(scene: Phaser.Scene, x: number, y: number, texture: string, frame?: string | number) {
+         super(scene, x, y, texture, frame);
 -        scene.physics.world.enableBody(this);
++        this.scene.sys.updateList.add(this);
++        this.scene.sys.displayList.add(this);
+         this.setScale(2);
 -        this.setCollideWorldBounds(true)
++        this.scene.physics.world.enableBody(this);
+         this.setImmovable(true);
++        this.setCollideWorldBounds(true);
++        this.setSize(32, 32); //edit the hitbox to better match the caracter model
+     }
+     move(x: number, y: number){
+         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);
+         } else if (this.body.velocity.x < 0) { //moving left
+             this.anims.playReverse(PlayerAnimationNames.WalkLeft, true);
+         } else if (this.body.velocity.y < 0) { //moving up
+             this.play(PlayerAnimationNames.WalkUp, true);
+         } else if (this.body.velocity.y > 0) { //moving down
+             this.play(PlayerAnimationNames.WalkDown, true);
+         }
+     }
+     
+     say(text: string) {
+         if (this.bubble) return;
+         this.bubble = new SpeechBubble(this.scene, this, text)
+         //todo make the buble destroy on player movement?
+         setTimeout(() => {
+             this.bubble.destroy();
+             this.bubble = null;
+         }, 3000)
+     }
+ }
index 71a3cbe391c3940415fc9bf6dcefca286e5c0863,ff9f5b5f92764aa821ae4a99ccb7bb971dd67059..d03a3152233bbe3c957768ae5b496878bca5f929
@@@ -44,33 -24,8 +44,34 @@@ export class GameManager implements Gam
          });
      }
  
 -    sharedUserPosition(UserPositions: any) {
 -        let Game: GameSceneInterface = this.GameScenes.find((Game: GameSceneInterface) => Game.RoomId === UserPositions.roomId);
 -        Game.sharedUserPosition(UserPositions)
 +    /**
 +     * Permit to create player in started room
 +     * @param RoomId
 +     * @param UserId
 +     */
 +    createCurrentPlayer(): void {
++        //Get started room send by the backend
 +        let game: GameSceneInterface = this.GameScenes.find((Game: GameSceneInterface) => Game.RoomId === ConnexionInstance.startedRoom);
 +        game.createCurrentPlayer(ConnexionInstance.userId);
 +        this.status = StatusGameManagerEnum.CURRENT_USER_CREATED;
 +    }
 +
 +    /**
 +     * Share position in game
 +     * @param ListMessageUserPosition
 +     */
 +    shareUserPosition(ListMessageUserPosition: ListMessageUserPositionInterface): void {
 +        if (this.status === StatusGameManagerEnum.IN_PROGRESS) {
 +            return;
 +        }
 +        try {
 +            let Game: GameSceneInterface = this.GameScenes.find((Game: GameSceneInterface) => Game.RoomId === ListMessageUserPosition.roomId);
 +            if (!Game) {
 +                return;
 +            }
 +            Game.shareUserPosition(ListMessageUserPosition.listUsersPosition)
 +        } catch (e) {
 +            console.error(e);
 +        }
      }
  }
index 61afdf688a3b1ba4a7b593fa84a180239ba02d5a,eab3df65fa4e009d1de2312af9404616a92151ea..a9a08fc62990311791d141b38e15d88c62e6fab0
@@@ -1,16 -1,27 +1,23 @@@
 -import {GameManagerInterface} from "./GameManager";
 -import {UserInputEvent, UserInputManager} from "../UserInput/UserInputManager";
 -import {getPlayerAnimations} from "../Player/Animation";
 -import {Player} from "../Player/Player";
 -import {NonPlayer} from "../NonPlayer/NonPlayer";
 +import {MapManagerInterface, MapManager} from "./MapManager";
 +import {GameManagerInterface, StatusGameManagerEnum} from "./GameManager";
 +import {MessageUserPositionInterface} from "../../Connexion";
  
+ export enum Textures {
+     Rock = 'rock',
+     Player = 'playerModel',
+     Map = 'map',
+     Tiles = 'tiles'
+ }
  export interface GameSceneInterface extends Phaser.Scene {
      RoomId : string;
 -    sharedUserPosition(data : []): void;
 +    createCurrentPlayer(UserId : string) : void;
 +    shareUserPosition(UsersPosition : Array<MessageUserPositionInterface>): void;
  }
  export class GameScene extends Phaser.Scene implements GameSceneInterface{
 -    //private MapManager : MapManagerInterface;
 +    private MapManager : MapManagerInterface;
 +    GameManager : GameManagerInterface;
      RoomId : string;
 -    private player: Player;
 -    private rock: Phaser.Physics.Arcade.Sprite;
 -    private userInputManager: UserInputManager;
 -    private otherPlayers: Phaser.Physics.Arcade.Group;
  
      constructor(RoomId : string, GameManager : GameManagerInterface) {
          super({
  
      //hook preload scene
      preload(): void {
-         this.load.image('tiles', 'maps/tiles.png');
-         this.load.tilemapTiledJSON('map', 'maps/map2.json');
-         this.load.spritesheet('player',
 -        this.load.image(Textures.Rock, 'resources/objects/rockSprite.png');
+         this.load.image(Textures.Tiles, 'maps/tiles.png');
+         this.load.tilemapTiledJSON(Textures.Map, 'maps/map2.json');
++        this.load.image(Textures.Rock, 'resources/objects/rockSprite.png');
+         this.load.spritesheet(Textures.Player,
              'resources/characters/pipoya/Male 01-1.png',
              { frameWidth: 32, frameHeight: 32 }
          );
index a66e0d377b9e586824394787861f827421d566bd,0000000000000000000000000000000000000000..3a91954c9c098706fd98eebcd11753e2dbcf48ff
mode 100644,000000..100644
--- /dev/null
@@@ -1,148 -1,0 +1,163 @@@
- import {GameSceneInterface} from "./GameScene";
 +import {CameraManager, CameraManagerInterface} from "./CameraManager";
 +import {RESOLUTION} from "../../Enum/EnvironmentVariable";
 +import {CurrentGamerInterface, GamerInterface, Player} from "../Player/Player";
-     keyZ: Phaser.Input.Keyboard.Key;
-     keyQ: Phaser.Input.Keyboard.Key;
-     keyS: Phaser.Input.Keyboard.Key;
-     keyD: Phaser.Input.Keyboard.Key;
-     keyRight: Phaser.Input.Keyboard.Key;
-     keyLeft: Phaser.Input.Keyboard.Key;
-     keyUp: Phaser.Input.Keyboard.Key;
-     keyDown: Phaser.Input.Keyboard.Key;
-     keyShift: Phaser.Input.Keyboard.Key;
++import {GameSceneInterface, Textures} from "./GameScene";
 +import {MessageUserPositionInterface} from "../../Connexion";
++import {NonPlayer} from "../NonPlayer/NonPlayer";
 +
 +export interface MapManagerInterface {
-     keyZ: Phaser.Input.Keyboard.Key;
-     keyQ: Phaser.Input.Keyboard.Key;
-     keyS: Phaser.Input.Keyboard.Key;
-     keyD: Phaser.Input.Keyboard.Key;
-     keyRight: Phaser.Input.Keyboard.Key;
-     keyLeft: Phaser.Input.Keyboard.Key;
-     keyUp: Phaser.Input.Keyboard.Key;
-     keyDown: Phaser.Input.Keyboard.Key;
-     keyShift: Phaser.Input.Keyboard.Key;
 +    Map: Phaser.Tilemaps.Tilemap;
 +    Terrain: Phaser.Tilemaps.Tileset;
 +    Camera: CameraManagerInterface;
 +    Scene: GameSceneInterface;
 +
 +    createCurrentPlayer(UserId : string): void;
 +    update(): void;
 +    updateOrCreateMapPlayer(UsersPosition : Array<MessageUserPositionInterface>): void;
 +}
 +export class MapManager implements MapManagerInterface{
-     MapPlayers : GamerInterface[];
 +    Terrain : Phaser.Tilemaps.Tileset;
 +    Camera: CameraManagerInterface;
 +    CurrentPlayer: CurrentGamerInterface;
-         this.Map.createStaticLayer("Calque 1", [this.Terrain], 0, 0);
-         this.Map.createStaticLayer("Calque 2", [this.Terrain], 0, 0);
++    MapPlayers : Phaser.Physics.Arcade.Group;
 +    Scene: GameSceneInterface;
 +    Map: Phaser.Tilemaps.Tilemap;
++    BottomLayer: Phaser.Tilemaps.StaticTilemapLayer;
++    TopLayer: Phaser.Tilemaps.StaticTilemapLayer;
 +    startX = (window.innerWidth / 2) / RESOLUTION;
 +    startY = (window.innerHeight / 2) / RESOLUTION;
 +
++    //entities
++    private rock: Phaser.Physics.Arcade.Sprite;
++
 +    constructor(scene: GameSceneInterface){
 +        this.Scene = scene;
 +
 +        //initalise map
 +        this.Map = this.Scene.add.tilemap("map");
 +        this.Terrain = this.Map.addTilesetImage("tiles", "tiles");
 +        this.Map.createStaticLayer("tiles", "tiles");
-         //initialise keyboard
-         this.initKeyBoard();
++        this.BottomLayer = this.Map.createStaticLayer("Calque 1", [this.Terrain], 0, 0).setDepth(-2);
++        this.TopLayer = this.Map.createStaticLayer("Calque 2", [this.Terrain], 0, 0).setDepth(-1);
++        this.Scene.physics.world.setBounds(0,0, this.Map.widthInPixels, this.Map.heightInPixels);
++
++        //add entitites
++        this.rock = this.Scene.physics.add.sprite(200, 400, Textures.Rock, 26).setImmovable(true);
++
++        //debug code
++        //debug code to see the collision hitbox of the object in the top layer
++        this.TopLayer.renderDebug(this.Scene.add.graphics(),{
++            tileColor: null, //non-colliding tiles
++            collidingTileColor: new Phaser.Display.Color(243, 134, 48, 200), // Colliding tiles,
++            faceColor: new Phaser.Display.Color(40, 39, 37, 255) // Colliding face edges
++        });
++
++        //init event click
++        this.EventToClickOnTile();
 +
-         this.MapPlayers = new Array<GamerInterface>();
 +        //initialise camera
 +        this.Camera = new CameraManager(this.Scene, this.Scene.cameras.main, this);
++
 +        //initialise list of other player
-     }
-     initKeyBoard() {
-         this.keyShift = this.Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SHIFT);
++        this.MapPlayers = this.Scene.physics.add.group({ immovable: true });
 +    }
 +
 +    createCurrentPlayer(UserId : string){
 +        //initialise player
 +        this.CurrentPlayer = new Player(
 +            UserId,
 +            this.Scene,
 +            this.startX,
 +            this.startY,
 +            this.Camera,
 +            this
 +        );
 +        this.CurrentPlayer.initAnimation();
-         this.keyZ = this.Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Z);
-         this.keyQ = this.Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Q);
-         this.keyS = this.Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.S);
-         this.keyD = this.Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.D);
 +
-         this.keyUp = this.Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.UP);
-         this.keyLeft = this.Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.LEFT);
-         this.keyDown = this.Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.DOWN);
-         this.keyRight = this.Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.RIGHT);
++        //create collision
++        this.Scene.physics.add.collider(this.CurrentPlayer, this.rock);
++        //add collision layer
++        this.Scene.physics.add.collider(this.CurrentPlayer, this.TopLayer);
++        this.TopLayer.setCollisionByProperty({collides:true});
++    }
 +
-         this.CurrentPlayer.move();
++    EventToClickOnTile(){
++        // debug code to get a tile properties by clicking on it
++        this.Scene.input.on("pointerdown", (pointer: Phaser.Input.Pointer)=>{
++            //pixel position toz tile position
++            let tile = this.Map.getTileAt(this.Map.worldToTileX(pointer.worldX), this.Map.worldToTileY(pointer.worldY));
++            if(tile){
++                //console.log("MapManager => tile => pointerdown", tile);
++                this.CurrentPlayer.say("Your touch " + tile.layer.name);
++            }
++        });
 +    }
 +
 +    update() : void {
-             let player = this.MapPlayers.find((player: Player) => userPosition.userId === player.userId);
++        this.CurrentPlayer.moveUser();
 +    }
 +
 +    /**
 +     * Create new player and clean the player on the map
 +     * @param UsersPosition
 +     */
 +    updateOrCreateMapPlayer(UsersPosition : Array<MessageUserPositionInterface>){
 +        if(!this.CurrentPlayer){
 +            return;
 +        }
 +
 +        //add or create new user
 +        UsersPosition.forEach((userPosition : MessageUserPositionInterface) => {
 +            if(userPosition.userId === this.CurrentPlayer.userId){
 +                return;
 +            }
-         let mapPlayers = new Array<Player>();
-         this.MapPlayers.forEach((player: Player) => {
++            let player = this.findPlayerInMap(userPosition.userId);
 +            if(!player){
 +                this.addPlayer(userPosition);
 +            }else{
 +                player.updatePosition(userPosition);
 +            }
 +        });
 +
 +        //clean map
-                 mapPlayers.push(player);
++        this.MapPlayers.getChildren().forEach((player: GamerInterface) => {
 +            if(UsersPosition.find((message : MessageUserPositionInterface) => message.userId === player.userId)){
-         this.MapPlayers = mapPlayers;
 +                return;
 +            }
 +            player.destroy();
++            this.MapPlayers.remove(player);
 +        });
-         this.MapPlayers.push(player);
-         player.updatePosition(MessageUserPosition)
++    }
++
++    private findPlayerInMap(UserId : string) : GamerInterface | null{
++        let player = this.MapPlayers.getChildren().find((player: Player) => UserId === player.userId);
++        if(!player){
++            return null;
++        }
++        return (player as GamerInterface);
 +    }
 +
 +    /**
 +     * Create new player
 +     * @param MessageUserPosition
 +     */
 +    addPlayer(MessageUserPosition : MessageUserPositionInterface){
 +        //initialise player
 +        let player = new Player(
 +            MessageUserPosition.userId,
 +            this.Scene,
 +            MessageUserPosition.position.x,
 +            MessageUserPosition.position.y,
 +            this.Camera,
 +            this
 +        );
 +        player.initAnimation();
++        this.MapPlayers.add(player);
++        player.updatePosition(MessageUserPosition);
++
++        //init colision
++        this.Scene.physics.add.collider(this.CurrentPlayer, player, (CurrentPlayer: CurrentGamerInterface, MapPlayer: GamerInterface) => {
++            MapPlayer.say("Hello, how are you ? ");
++        });
 +    }
 +}
index 0000000000000000000000000000000000000000,f2d748ab7ef86cc0fc6993f536d86b4880e016c2..63012e464ac387847bbe6afde364dd81f530b511
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,31 +1,40 @@@
+ import {PlayableCaracter} from "../Entity/PlayableCaracter";
+ import {Textures} from "../Game/GameScene";
+ import {UserInputEvent} from "../UserInput/UserInputManager";
+ import {Player} from "../Player/Player";
++import {MessageUserPositionInterface} from "../../Connexion";
++import {playAnimation} from "../Player/Animation";
+ export class NonPlayer extends PlayableCaracter {
+     
+     isFleeing: boolean = false;
+     fleeingDirection:any = null //todo create a vector class
+     
+     constructor(scene: Phaser.Scene, x: number, y: number) {
+         super(scene, x, y, Textures.Player, 1);
+         this.setSize(32, 32); //edit the hitbox to better match the caracter model
+     }
++
++    updatePosition(MessageUserPosition : MessageUserPositionInterface){
++        playAnimation(this, MessageUserPosition.position.direction);
++        this.setX(MessageUserPosition.position.x);
++        this.setY(MessageUserPosition.position.y);
++    }
++
+     fleeFrom(player:Player) {
+         if (this.isFleeing) return;
+         this.say("Don't touch me!");
+         this.isFleeing = true;
+         
+         setTimeout(() => {
+             this.say("Feww, I escaped.");
+             this.isFleeing = false
+             this.fleeingDirection = null
+         }, 3000);
+         
+         let vectorX = this.x - player.x; 
+         let vectorY = this.y - player.y;
+         this.fleeingDirection = {x: vectorX, y: vectorY}
+     }
+ }
index eb8298f452d047be825d11c279a6ff0e3027e14d,48dc3ac9021e9d818fd3565a54b60db92943ed75..48f346824d7ac689c14c196981ee84bb480f32c8
@@@ -1,3 -1,6 +1,5 @@@
 -import {PlayableCaracter} from "../Entity/PlayableCaracter";
+ import {Textures} from "../Game/GameScene";
  interface AnimationData {
      key: string;
      frameRate: number;
@@@ -22,24 -25,24 +24,24 @@@ export const getPlayerAnimations = (): 
          frameStart: 0,
          frameEnd: 2,
          frameRate: 10,
 -        //repeat: -1
 +        repeat: -1
      }, {
          key: PlayerAnimationNames.WalkLeft,
-         frameModel: PlayerValue,
+         frameModel: Textures.Player,
          frameStart: 3,
          frameEnd: 5,
          frameRate: 10,
 -        //repeat: -1
 +        repeat: -1
      }, {
          key: PlayerAnimationNames.WalkRight,
-         frameModel: PlayerValue,
+         frameModel: Textures.Player,
          frameStart: 6,
          frameEnd: 8,
          frameRate: 10,
 -        //repeat: -1
 +        repeat: -1
      }, {
          key: PlayerAnimationNames.WalkUp,
-         frameModel: PlayerValue,
+         frameModel: Textures.Player,
          frameStart: 9,
          frameEnd: 11,
          frameRate: 10,
      }];
  };
  
 -export const playAnimation = (Player : PlayableCaracter, direction : string) => {
 -    //if (direction === 'none') return;
 -    //Player.play(direction, true);
 -};
 +export const playAnimation = (Player : Phaser.GameObjects.Sprite, direction : string) => {
 +    if (!Player.anims.currentAnim || Player.anims.currentAnim.key !== direction) {
 +        Player.anims.play(direction);
 +    } else if (direction === PlayerAnimationNames.None && Player.anims.currentAnim) {
 +        Player.anims.currentAnim.destroy();
 +    }
- };
++}
index f256bbf4019601bf30a770bd361287deffc054c5,8c9b462bb63ccfd683c940712d1bb6fa5f1d5ebe..78aa5801c4da39a4cc611eb342abc47513d00c74
- import {MapManagerInterface} from "../Game/MapManager";
  import {getPlayerAnimations, playAnimation, PlayerAnimationNames} from "./Animation";
- import {GameSceneInterface} from "../Game/GameScene";
+ import {GameSceneInterface, Textures} from "../Game/GameScene";
  import {ConnexionInstance} from "../Game/GameManager";
 -import {ActiveEventList, UserInputEvent} from "../UserInput/UserInputManager";
 +import {CameraManagerInterface} from "../Game/CameraManager";
 +import {MessageUserPositionInterface} from "../../Connexion";
++import {ActiveEventList, UserInputEvent, UserInputManager} from "../UserInput/UserInputManager";
+ import {PlayableCaracter} from "../Entity/PlayableCaracter";
++import {MapManagerInterface} from "../Game/MapManager";
  
- export interface CurrentGamerInterface{
 -export class Player extends PlayableCaracter{
 -    
 -    constructor(scene: Phaser.Scene, x: number, y: number) {
 -        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
++export interface CurrentGamerInterface extends PlayableCaracter{
 +    userId : string;
 +    MapManager : MapManagerInterface;
 +    PlayerValue : string;
 +    CameraManager: CameraManagerInterface;
 +    initAnimation() : void;
-     move() : void;
++    moveUser() : void;
++    say(text : string) : void;
 +}
 +
- export interface GamerInterface{
++export interface GamerInterface extends PlayableCaracter{
 +    userId : string;
 +    MapManager : MapManagerInterface;
 +    PlayerValue : string;
 +    CameraManager: CameraManagerInterface;
 +    initAnimation() : void;
 +    updatePosition(MessageUserPosition : MessageUserPositionInterface) : void;
++    say(text : string) : void;
 +}
 +
- export class Player extends Phaser.GameObjects.Sprite implements CurrentGamerInterface, GamerInterface{
++export class Player extends PlayableCaracter implements CurrentGamerInterface, GamerInterface{
 +    userId : string;
 +    MapManager : MapManagerInterface;
 +    PlayerValue : string;
 +    CameraManager: CameraManagerInterface;
++    userInputManager: UserInputManager;
 +
 +    constructor(
 +        userId: string,
 +        Scene : GameSceneInterface,
 +        x : number,
 +        y : number,
 +        CameraManager: CameraManagerInterface,
 +        MapManager: MapManagerInterface,
-         PlayerValue : string = "player"
++        PlayerValue : string = Textures.Player
 +    ) {
-         super(Scene, x, y, PlayerValue);
++        super(Scene, x, y, PlayerValue, 1);
++
++        //create input to move
++        this.userInputManager = new UserInputManager(Scene);
++
++        //set data
 +        this.userId = userId;
 +        this.PlayerValue = PlayerValue;
-         Scene.add.existing(this);
 +        this.MapManager = MapManager;
 +        this.CameraManager = CameraManager;
++
++        //the current player model should be push away by other players to prevent conflict
++        this.setImmovable(false);
++        //edit the hitbox to better match the caracter model
++        this.setSize(32, 32);
 +    }
 +
-     initAnimation() : void{
-         getPlayerAnimations(this.PlayerValue).forEach(d => {
++    initAnimation() : void {
++        getPlayerAnimations().forEach(d => {
 +            this.scene.anims.create({
 +                key: d.key,
-                 frames: this.scene.anims.generateFrameNumbers(d.frameModel, { start: d.frameStart, end: d.frameEnd }),
++                frames: this.scene.anims.generateFrameNumbers(d.frameModel, {start: d.frameStart, end: d.frameEnd}),
 +                frameRate: d.frameRate,
 +                repeat: d.repeat
 +            });
 +        })
 +    }
 +
-     move() : void{
++    moveUser() : void {
 +        //if user client on shift, camera and player speed
-         let speedMultiplier = this.MapManager.keyShift.isDown ? 5 : 1;
++        //let speedMultiplier = this.MapManager.keyShift.isDown ? 5 : 1;
 +        let haveMove = false;
 +        let direction = null;
 +
-         if((this.MapManager.keyZ.isDown || this.MapManager.keyUp.isDown)){
-             if(!this.CanMoveUp()){
++        let activeEvents = this.userInputManager.getEventListForGameTick();
++        let speedMultiplier = activeEvents.get(UserInputEvent.SpeedUp) ? 500 : 100;
++
++        if (activeEvents.get(UserInputEvent.MoveUp)) {
++            if (!this.CanMoveUp()) {
 +                return;
 +            }
-             playAnimation(this, PlayerAnimationNames.WalkUp);
-             this.setY(this.y - (2 * speedMultiplier));
++            this.move(0, -speedMultiplier);
 +            haveMove = true;
 +            direction = PlayerAnimationNames.WalkUp;
 +        }
-         if((this.MapManager.keyQ.isDown || this.MapManager.keyLeft.isDown)){
-             if(!this.CanMoveLeft()){
++        if (activeEvents.get(UserInputEvent.MoveLeft)) {
++            if (!this.CanMoveLeft()) {
 +                return;
 +            }
-             playAnimation(this, PlayerAnimationNames.WalkLeft);
-             this.setX(this.x - (2 * speedMultiplier));
++            this.move(-speedMultiplier, 0);
 +            haveMove = true;
 +            direction = PlayerAnimationNames.WalkLeft;
 +        }
-         if((this.MapManager.keyS.isDown || this.MapManager.keyDown.isDown)){
-             if(!this.CanMoveDown()){
++        if (activeEvents.get(UserInputEvent.MoveDown)) {
++            if (!this.CanMoveDown()) {
 +                return;
 +            }
-             playAnimation(this, PlayerAnimationNames.WalkDown);
-             this.setY(this.y + (2 * speedMultiplier));
++            this.move(0, speedMultiplier);
 +            haveMove = true;
 +            direction = PlayerAnimationNames.WalkDown;
 +        }
-         if((this.MapManager.keyD.isDown || this.MapManager.keyRight.isDown)){
-             if(!this.CanMoveRight()){
++        if (activeEvents.get(UserInputEvent.MoveRight)) {
++            if (!this.CanMoveRight()) {
 +                return;
 +            }
-             playAnimation(this, PlayerAnimationNames.WalkRight);
-             this.setX(this.x + (2 * speedMultiplier));
++            this.move(speedMultiplier, 0);
 +            haveMove = true;
 +            direction = PlayerAnimationNames.WalkRight;
 +        }
-         if(!haveMove){
-             playAnimation(this, PlayerAnimationNames.None);
++        if (!haveMove) {
 +            direction = PlayerAnimationNames.None;
++            this.move(0, 0)
 +        }
 +        this.sharePosition(direction);
 +        this.CameraManager.moveCamera(this);
 +    }
 +
 +    private sharePosition(direction : string){
 +        if(ConnexionInstance) {
 +            ConnexionInstance.sharePosition((this.scene as GameSceneInterface).RoomId, this.x, this.y, direction);
 +        }
 +    }
 +
 +    private CanMoveUp(){
 +        return this.y > 0;
 +    }
 +
 +    private CanMoveLeft(){
 +        return this.x > 0;
 +    }
 +
 +    private CanMoveDown(){
 +        return this.MapManager.Map.heightInPixels > this.y;
 +    }
 +
-     private CanMoveRight(){
++    private CanMoveRight() {
 +        return this.MapManager.Map.widthInPixels > this.x;
      }
  
+     stop() {
+         this.setVelocity(0, 0)
+     }
++
 +    updatePosition(MessageUserPosition : MessageUserPositionInterface){
 +        playAnimation(this, MessageUserPosition.position.direction);
 +        this.setX(MessageUserPosition.position.x);
 +        this.setY(MessageUserPosition.position.y);
 +    }
  }
index 0000000000000000000000000000000000000000,1e5e6e13a1cb5e15a5bcc48029c7dc084a28ff69..6c5b32c2ba1c1c020f874d38f77a166c2e5adcc7
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,68 +1,68 @@@
 -    private data:any;
+ import Map = Phaser.Structs.Map;
+ import {GameSceneInterface} from "../Game/GameScene";
+ interface UserInputManagerDatum {
+     keyCode: number;
+     keyInstance: Phaser.Input.Keyboard.Key;
+     event: UserInputEvent
+ }
+ export enum UserInputEvent {
+     MoveLeft = 1,
+     MoveUp,
+     MoveRight,
+     MoveDown,
+     SpeedUp,
+     Interact,
+     Shout,
+ }
+ //we cannot the map structure so we have to create a replacment
+ export class ActiveEventList {
 -        this.data = {};
++    private KeysCode : any;
+     constructor() {
 -        return this.data[event] || false;
++        this.KeysCode = {};
+     }
+     get(event: UserInputEvent): boolean {
 -        return this.data[event] = true;
++        return this.KeysCode[event] || false;
+     }
+     set(event: UserInputEvent, value: boolean): boolean {
 -    private data: UserInputManagerDatum[] = [
++        return this.KeysCode[event] = true;
+     }
+ } 
+ //this class is responsible for catching user inputs and listing all active user actions at every game tick events.
+ export class UserInputManager {
 -        this.data.forEach(d => {
++    private KeysCode: UserInputManagerDatum[] = [
+         {keyCode: Phaser.Input.Keyboard.KeyCodes.Z, event: UserInputEvent.MoveUp, keyInstance: null},
+         {keyCode: Phaser.Input.Keyboard.KeyCodes.Q, event: UserInputEvent.MoveLeft, keyInstance: null},
+         {keyCode: Phaser.Input.Keyboard.KeyCodes.S, event: UserInputEvent.MoveDown, keyInstance: null},
+         {keyCode: Phaser.Input.Keyboard.KeyCodes.D, event: UserInputEvent.MoveRight, keyInstance: null},
+         
+         {keyCode: Phaser.Input.Keyboard.KeyCodes.UP, event: UserInputEvent.MoveUp, keyInstance: null},
+         {keyCode: Phaser.Input.Keyboard.KeyCodes.LEFT, event: UserInputEvent.MoveLeft, keyInstance: null},
+         {keyCode: Phaser.Input.Keyboard.KeyCodes.DOWN, event: UserInputEvent.MoveDown, keyInstance: null},
+         {keyCode: Phaser.Input.Keyboard.KeyCodes.RIGHT, event: UserInputEvent.MoveRight, keyInstance: null},
+         
+         {keyCode: Phaser.Input.Keyboard.KeyCodes.SHIFT, event: UserInputEvent.SpeedUp, keyInstance: null},
+         
+         {keyCode: Phaser.Input.Keyboard.KeyCodes.E, event: UserInputEvent.Interact, keyInstance: null},
+         {keyCode: Phaser.Input.Keyboard.KeyCodes.F, event: UserInputEvent.Shout, keyInstance: null},
+     ];
+     
+     constructor(Scene : GameSceneInterface) {
 -        this.data.forEach(d => {
++        this.KeysCode.forEach(d => {
+             d.keyInstance = Scene.input.keyboard.addKey(d.keyCode);
+         });
+     }
+     getEventListForGameTick(): ActiveEventList {
+         let eventsMap = new ActiveEventList();
++        this.KeysCode.forEach(d => {
+             if (d. keyInstance.isDown) {
+                 eventsMap.set(d.event, true);
+             }
+         });
+         return eventsMap;
+     }
+ }
index 2a18110d195034af2af01e186c8a1e0f385c6ba2,a366078adcaa4d4c054e88e3a7368d785e1102f5..5d90a19e784c64ed0b8997d029a1dd9e3dc7d39b
@@@ -12,12 -12,16 +12,18 @@@ const config: GameConfig = 
      parent: "game",
      scene: gameManager.GameScenes,
      zoom: RESOLUTION,
+     physics: {
+         default: "arcade",
+         arcade: {
+             debug: true
+         }
+     }
  };
  
 -let game = new Phaser.Game(config);
 +gameManager.createGame().then(() => {
 +    let game = new Phaser.Game(config);
  
 -window.addEventListener('resize', function (event) {
 -    game.scale.resize(window.innerWidth / RESOLUTION, window.innerHeight / RESOLUTION);
 +    window.addEventListener('resize', function (event) {
 +        game.scale.resize(window.innerWidth / RESOLUTION, window.innerHeight / RESOLUTION);
 +    });
  });