Add Door object stub
authorMegaBrutal <code+git@megabrutal.com>
Fri, 7 Sep 2018 23:05:00 +0000 (01:05 +0200)
committerMegaBrutal <code+git@megabrutal.com>
Fri, 7 Sep 2018 23:05:00 +0000 (01:05 +0200)
Added Door object stub and code to create doors.
Doors are not rendered with respective rotation
and they don't collide or work yet.

modified:   wgj58.js

wgj58.js

index d29f4e8fe3f37bf1a4d6f929150055e23071e9b3..e034b01a3eeb3155b41d0c874e1150c64147cc79 100644 (file)
--- a/wgj58.js
+++ b/wgj58.js
@@ -39,6 +39,14 @@ class Dialogue {
        }
 }
 
+class Door extends Phaser.TileSprite {
+       constructor(x, y, name, vector, longpanel) {
+               super(game, x, y, 64, 64, 'objects');
+               this.tilePosition = new Phaser.Point(-64, -64);
+               console.log("New door:", this);
+       }
+}
+
 class Player extends Phaser.Sprite {
        constructor(x, y) {
                super(game, x, y, 'player');
@@ -381,12 +389,14 @@ class GameLogic {
        constructor() {
                this.player = this.clara = this.carlos = this.saiki = this.peter = this.bianca = null;
                this.gameinterface = new GameInterface(game, game.stage);
+               //this.doors = game.add.group(game.world, "doors");
                this.last_menuselect = 0;
        }
 
        createObject(object) {
                switch (object.type) {
                        case 'spawnpoint':              this.createCharacter(object); break;
+                       case 'door':                    this.createDoor(object); break;
                        case '':                                console.error("Object type is empty:", object); break;
                        default:                                console.error("Unknown object type:", object);
                }
@@ -413,6 +423,19 @@ class GameLogic {
                console.log(newChar);
        }
 
+       createDoor(object) {
+               var vector;
+               switch (object.rotation) {
+                       case undefined:
+                       case 0:         vector = new Phaser.Point( -1,  0); break;
+                       case 90:        vector = new Phaser.Point(  0, -1); break;
+                       case 180:       vector = new Phaser.Point(  1,  0); break;
+                       case 270:       vector = new Phaser.Point(  0,  1); break;
+                       default:        console.error("Invalid rotation:", object.rotation);
+               }
+               this.doors.add(new Door(object.x, object.y, object.name, vector, object.properties.longpanel));
+       }
+
        callMenu(menuitem) {
                console.log("Menu callback received:", menuitem);
                this.last_menuselect = game.time.now;
@@ -493,6 +516,10 @@ class GamePlay extends Phaser.State {
                map.setCollisionBetween(1, 100, true, this.layer_walls);
                this.layer_furniture = map.createLayer('furniture');
                map.setCollisionBetween(1, 100, true, this.layer_furniture);
+
+               // FIXME: Don't create a group here like this, it's too ugly! Now I have it here due to the display order.
+               logic.doors = game.add.group(game.world, "doors");
+
                map.objects['objects'].forEach(function(o) { logic.createObject(o); });
                console.log(map.objects);