Correct feedback @moufmouf
authorgparant <g.parant@thecodingmachine.com>
Sun, 10 May 2020 12:49:49 +0000 (14:49 +0200)
committergparant <g.parant@thecodingmachine.com>
Sun, 10 May 2020 12:49:49 +0000 (14:49 +0200)
README.md
doc/images/exit_layer_map.png [new file with mode: 0644]
front/src/Phaser/Game/GameScene.ts

index c36aac6b308dacd0ed88c076bcd392c8e07e40d9..8fdee4e81eda17c05e3a05cbe65a0f952c1d3a5e 100644 (file)
--- a/README.md
+++ b/README.md
@@ -45,6 +45,12 @@ A few things to notice:
 
 ![](doc/images/tiled_screenshot_1.png)
 
+If you have exit scene
+- You must create layer "exit". The layer have cases where the gamer can switch to the next scene.
+- In layer properties, you must add "exitSceneKey" property. It represent a key map of the next scene. Be careful, if you want that the next map will be correctly loaded, you must check that the map exists in the list of the maps application. The variable that represents maps in the application is "ROOMS" constant variable.
+
+![](doc/images/exit_layer_map.png)
+
 ### MacOS developers, your environment with Vagrant
 
 If you are using MacOS, you can increase Docker performance using Vagrant. If you want more explanations, you can read [this medium article](https://medium.com/better-programming/vagrant-to-increase-docker-performance-with-macos-25b354b0c65c).
diff --git a/doc/images/exit_layer_map.png b/doc/images/exit_layer_map.png
new file mode 100644 (file)
index 0000000..122610c
Binary files /dev/null and b/doc/images/exit_layer_map.png differ
index 09bf38f2815979e655cd890e742e4d51de1d574d..26c2fc355ba036d726977d3134d42b1e0c7e7d1c 100644 (file)
@@ -108,7 +108,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface, Creat
                 this.addLayer(this.Map.createStaticLayer(layer.name, this.Terrains, 0, 0).setDepth(depth));
             }
             if (layer.type === 'tilelayer' && layer.name === "exit") {
-                this.loadNextGame(layer);
+                this.loadNextGame(layer, this.map.width, this.map.tilewidth, this.map.tileheight);
             }
             if (layer.type === 'tilelayer' && layer.name === "start") {
                 this.startUser(layer);
@@ -155,15 +155,19 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface, Creat
     }
 
     /**
-     * @param layer : ITiledMapLayer
+     *
+     * @param layer
+     * @param mapWidth
+     * @param tileWidth
+     * @param tileHeight
      */
-    private loadNextGame(layer: ITiledMapLayer){
+    private loadNextGame(layer: ITiledMapLayer, mapWidth: number, tileWidth: number, tileHeight: number){
         let properties : any = layer.properties;
         let nextSceneKey = properties.find((property:any) => property.name === "exitSceneKey");
         let nextMap : MapObject = gameManager.Maps.find((map: MapObject) => map.key === nextSceneKey.value);
 
         let gameIndex = this.scene.getIndex(nextMap.key);
-        let game = null;
+        let game : Phaser.Scene = null;
         if(gameIndex === -1){
             game = new GameScene(nextMap.key, `${API_URL}${nextMap.url}`);
             this.scene.add(nextSceneKey, game, false);
@@ -173,20 +177,20 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface, Creat
         if(!game){
             return;
         }
-
         let tiles : any = layer.data;
         tiles.forEach((objectKey : number, key: number) => {
             if(objectKey === 0){
                 return;
             }
-            let y = (key / 45);
-            y = parseInt(`${y}`);
-            let x = key - (y * 46);
+            //key + 1 because the start x = 0;
+            let y : number = parseInt(((key + 1) / mapWidth).toString());
+            let x : number = key - (y * mapWidth);
+            //push and save switching case
             this.PositionNextScene.push({
-                xStart: (x * 32),
-                yStart: (y * 32),
-                xEnd: ((x +1) * 32),
-                yEnd: ((y + 1) * 32),
+                xStart: (x * tileWidth),
+                yStart: (y * tileWidth),
+                xEnd: ((x +1) * tileHeight),
+                yEnd: ((y + 1) * tileHeight),
                 key: nextMap.key
             })
         });