From a72760aadcd1a753f785ae0e7459b7a8c523e075 Mon Sep 17 00:00:00 2001 From: MegaBrutal Date: Sat, 8 Sep 2018 01:05:00 +0200 Subject: [PATCH] Add Door object stub 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 | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/wgj58.js b/wgj58.js index d29f4e8..e034b01 100644 --- 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); -- 2.34.1