deleted cameraManager, use camera follow code instead
authorkharhamel <oognic@gmail.com>
Mon, 13 Apr 2020 17:56:41 +0000 (19:56 +0200)
committerkharhamel <oognic@gmail.com>
Mon, 13 Apr 2020 17:57:14 +0000 (19:57 +0200)
front/src/Enum/EnvironmentVariable.ts
front/src/Phaser/Game/CameraManager.ts [deleted file]
front/src/Phaser/Game/GameScene.ts
front/src/Phaser/Player/Player.ts

index b4dd4f26d0fc674a7e694327b0d9a1d37d781567..db5b912c5fbf10dafcd520316861ada3525f6be4 100644 (file)
@@ -2,10 +2,12 @@ const DEBUG_MODE: boolean = !!process.env.DEBUG_MODE || false;
 const API_URL = process.env.API_URL || "http://api.workadventure.localhost";
 const ROOM = [process.env.ROOM || "THECODINGMACHINE"];
 const RESOLUTION = 2;
+const ZOOM_LEVEL = 3/4;
 
 export {
     DEBUG_MODE,
     API_URL,
     RESOLUTION,
+    ZOOM_LEVEL,
     ROOM
 }
\ No newline at end of file
diff --git a/front/src/Phaser/Game/CameraManager.ts b/front/src/Phaser/Game/CameraManager.ts
deleted file mode 100644 (file)
index 3b2dc06..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-import {RESOLUTION} from "../../Enum/EnvironmentVariable";
-import {Player} from "../Player/Player";
-import {GameSceneInterface} from "./GameScene";
-
-export interface CameraManagerInterface {
-    moveCamera(CurrentPlayer : Player) : void;
-}
-
-export class CameraManager implements CameraManagerInterface{
-    Scene : GameSceneInterface;
-    Camera : Phaser.Cameras.Scene2D.Camera;
-
-    constructor(
-        Scene: GameSceneInterface,
-        Camera : Phaser.Cameras.Scene2D.Camera,
-    ) {
-        this.Scene = Scene;
-        this.Camera = Camera;
-    }
-
-    moveCamera(CurrentPlayer : Player): void {
-        //center of camera
-        let startX = ((window.innerWidth / 2) / RESOLUTION);
-        let startY = ((window.innerHeight / 2) / RESOLUTION);
-
-        let limit = {
-            top: startY,
-            left: startX,
-            bottom : this.Scene.Map.heightInPixels - startY,
-            right: this.Scene.Map.widthInPixels - startX,
-        };
-
-        if(CurrentPlayer.x < limit.left){
-            this.Camera.scrollX = 0;
-        }else if(CurrentPlayer.x > limit.right){
-            this.Camera.scrollX = (limit.right - startX);
-        }else {
-            this.Camera.scrollX = (CurrentPlayer.x - startX);
-        }
-
-        if(CurrentPlayer.y < limit.top){
-            this.Camera.scrollY = 0;
-        }else if(CurrentPlayer.y > limit.bottom){
-            this.Camera.scrollY = (limit.bottom - startY);
-        }else {
-            this.Camera.scrollY = (CurrentPlayer.y - startY);
-        }
-    }
-}
\ No newline at end of file
index 88514a6e4f856a3e55e0afceeb64d82f1e736252..582312dcf96d4359b8caa4f898124bfc9360535c 100644 (file)
@@ -1,8 +1,7 @@
 import {GameManagerInterface, StatusGameManagerEnum} from "./GameManager";
 import {MessageUserPositionInterface} from "../../Connexion";
-import {CameraManager, CameraManagerInterface} from "./CameraManager";
 import {CurrentGamerInterface, GamerInterface, Player} from "../Player/Player";
-import {DEBUG_MODE, RESOLUTION} from "../../Enum/EnvironmentVariable";
+import {DEBUG_MODE, RESOLUTION, ZOOM_LEVEL} from "../../Enum/EnvironmentVariable";
 import Tile = Phaser.Tilemaps.Tile;
 
 export enum Textures {
@@ -22,7 +21,6 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
     GameManager : GameManagerInterface;
     RoomId : string;
     Terrain : Phaser.Tilemaps.Tileset;
-    Camera: CameraManagerInterface;
     CurrentPlayer: CurrentGamerInterface;
     MapPlayers : Phaser.Physics.Arcade.Group;
     Map: Phaser.Tilemaps.Tilemap;
@@ -76,14 +74,22 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
         //init event click
         this.EventToClickOnTile();
 
-        //initialise camera
-        this.Camera = new CameraManager(this, this.cameras.main);
-
         //initialise list of other player
         this.MapPlayers = this.physics.add.group({ immovable: true });
 
         //notify game manager can to create currentUser in map
         this.GameManager.createCurrentPlayer();
+
+
+        //initialise camera
+        this.initCamera();
+    }
+
+    //todo: in a dedicated class/function?
+    initCamera() {
+        this.cameras.main.setBounds(0,0, this.Map.widthInPixels, this.Map.heightInPixels);
+        this.cameras.main.startFollow(this.CurrentPlayer);
+        this.cameras.main.setZoom(ZOOM_LEVEL);
     }
 
     addLayer(Layer : Phaser.Tilemaps.StaticTilemapLayer){
@@ -128,7 +134,6 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
             this,
             this.startX,
             this.startY,
-            this.Camera,
         );
         this.CurrentPlayer.initAnimation();
 
@@ -212,7 +217,6 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
             this,
             MessageUserPosition.position.x,
             MessageUserPosition.position.y,
-            this.Camera,
         );
         player.initAnimation();
         this.MapPlayers.add(player);
index e2d7d6923a76990f5fd3bd1faf3da1f79d826bc5..4cd1a6aab8f9f2b447fc06c18870d1f1b4bc3503 100644 (file)
@@ -1,7 +1,6 @@
 import {getPlayerAnimations, playAnimation, PlayerAnimationNames} from "./Animation";
 import {GameSceneInterface, Textures} from "../Game/GameScene";
 import {ConnexionInstance} from "../Game/GameManager";
-import {CameraManagerInterface} from "../Game/CameraManager";
 import {MessageUserPositionInterface} from "../../Connexion";
 import {ActiveEventList, UserInputEvent, UserInputManager} from "../UserInput/UserInputManager";
 import {PlayableCaracter} from "../Entity/PlayableCaracter";
@@ -9,7 +8,6 @@ import {PlayableCaracter} from "../Entity/PlayableCaracter";
 export interface CurrentGamerInterface extends PlayableCaracter{
     userId : string;
     PlayerValue : string;
-    CameraManager: CameraManagerInterface;
     initAnimation() : void;
     moveUser() : void;
     say(text : string) : void;
@@ -18,7 +16,6 @@ export interface CurrentGamerInterface extends PlayableCaracter{
 export interface GamerInterface extends PlayableCaracter{
     userId : string;
     PlayerValue : string;
-    CameraManager: CameraManagerInterface;
     initAnimation() : void;
     updatePosition(MessageUserPosition : MessageUserPositionInterface) : void;
     say(text : string) : void;
@@ -27,7 +24,6 @@ export interface GamerInterface extends PlayableCaracter{
 export class Player extends PlayableCaracter implements CurrentGamerInterface, GamerInterface {
     userId: string;
     PlayerValue: string;
-    CameraManager: CameraManagerInterface;
     userInputManager: UserInputManager;
 
     constructor(
@@ -35,7 +31,6 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
         Scene: GameSceneInterface,
         x: number,
         y: number,
-        CameraManager: CameraManagerInterface,
         PlayerValue: string = Textures.Player
     ) {
         super(Scene, x, y, PlayerValue, 1);
@@ -46,7 +41,6 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
         //set data
         this.userId = userId;
         this.PlayerValue = PlayerValue;
-        this.CameraManager = CameraManager;
 
         //the current player model should be push away by other players to prevent conflict
         this.setImmovable(false);
@@ -96,7 +90,6 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
             this.stop();
         }
         this.sharePosition(direction);
-        this.CameraManager.moveCamera(this);
     }
 
     private sharePosition(direction: string) {