Add methods to open & close doors
authorMegaBrutal <code+git@megabrutal.com>
Mon, 10 Sep 2018 23:50:00 +0000 (01:50 +0200)
committerMegaBrutal <code+git@megabrutal.com>
Mon, 10 Sep 2018 23:50:00 +0000 (01:50 +0200)
Doors can be controlled through GameLogic.openDoor and
GameLogic.closeDoor methods.
Clara opens and closes the doors during conversation.

modified:   wgj58.js

wgj58.js

index 988d662..8fe220f 100644 (file)
--- 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)) {