From: MegaBrutal Date: Mon, 10 Sep 2018 23:50:00 +0000 (+0200) Subject: Add methods to open & close doors X-Git-Tag: early-release~28 X-Git-Url: http://git.megabrutal.com/?p=wgj58.git;a=commitdiff_plain;h=d9b347a8804fedc728550ae5372306a670b5b6a8;hp=6252fb1168fd9caedbbad193159543b24013759d Add methods to open & close doors Doors can be controlled through GameLogic.openDoor and GameLogic.closeDoor methods. Clara opens and closes the doors during conversation. modified: wgj58.js --- diff --git a/wgj58.js b/wgj58.js index 988d662..8fe220f 100644 --- a/wgj58.js +++ b/wgj58.js @@ -42,6 +42,7 @@ class Dialogue { class Door extends Phaser.TileSprite { constructor(x, y, name, rotation, vector, longpanel) { super(game, x, y, 64, 64, 'objects'); + this.name = name; if (!longpanel) { this.anchor = new Phaser.Point(0.5, 0.5); this.tilePosition = new Phaser.Point(-64, -64); @@ -58,18 +59,20 @@ class Door extends Phaser.TileSprite { this.closetween = game.add.tween(this).to({ x: this.position.x, y: this.position.y }, 1000, Phaser.Easing.Sinusoidal.InOut, false, 0, 0, false); this.openposition = Phaser.Point.add(this.position, this.openvector); this.opentween = game.add.tween(this).to({ x: this.openposition.x, y: this.openposition.y }, 1000, Phaser.Easing.Sinusoidal.InOut, false, 0, 0, false); + this.isOpen = false; } - update() { - if ((this.opentween) && (game.time.now > 5000)) { - console.log(game.time.now, "Opening door."); + open() { + if (!this.isOpen) { this.opentween.start(); - this.opentween = null; + this.isOpen = true; } - else if ((this.closetween) && (game.time.now > 10000)) { - console.log(game.time.now, "Closing door."); + } + + close() { + if (this.isOpen) { this.closetween.start(); - this.closetween = null; + this.isOpen = false; } } } @@ -197,6 +200,7 @@ class NPC_Clara extends GameNPC { { actor: this, text: "Wish it worked like that... Is it some superstition like the belief that having an umbrella with you prevents rain?" }, { actor: logic.player, text: "Nah, that actually works; it's not a superstition, but Murphy's Law!" }, { actor: this, text: "If you say so..." } ] )); + logic.openDoor("cutedoor"); break; case 1: logic.gameinterface.talk(new Dialogue( [ { actor: this, text: "John, have you ever thought about losing your employee card?" }, @@ -208,6 +212,7 @@ class NPC_Clara extends GameNPC { { actor: this, text: "If I had no card, would I still exist?" }, { actor: logic.player, text: "..." }, { actor: logic.player, text: "You sound very philosophical today." } ] )); + logic.closeDoor("cutedoor"); break; case 2: case 3: @@ -495,6 +500,15 @@ class GameLogic { } } + openDoor(doorname) { + console.log("Opening doors."); + this.doors.children.forEach(function(o) { if (o.name == doorname) o.open(); }); + } + + closeDoor(doorname) { + this.doors.children.forEach(function(o) { if (o.name == doorname) o.close(); }); + } + update() { if ((game.input.keyboard.isDown(Phaser.Keyboard.ENTER)) && (hasTimePassed(this.last_menuselect, WAIT_MENUSTEP))) { if ((this.player.interactablenpc) && (this.player.interactablenpc.interactable) && (!this.gameinterface.inMenu) && (!this.gameinterface.inTalk)) {