X-Git-Url: http://git.megabrutal.com/?p=wgj58.git;a=blobdiff_plain;f=wgj58.js;h=fcfa0f408c164a3c93d727d140415489ed860db5;hp=988d662e13d7a2fbfaa8d7f2f18e134d20bb7714;hb=d988949db6969ebd6c45a95001b6f2169bf967a3;hpb=cb29becc715c01e495228174666fdd66a64ad7ac diff --git a/wgj58.js b/wgj58.js index 988d662..fcfa0f4 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); @@ -54,24 +55,31 @@ class Door extends Phaser.TileSprite { this.openvector = Phaser.Point.multiply(vector, new Phaser.Point(116, 116)); } this.rotation = rotation * (Math.PI / 180); - console.log("Calculated vector:", this.openvector); 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; + game.physics.arcade.enable(this); + this.body.immovable = true; } - 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; } } + + update() { + game.debug.body(this); + } } class Player extends Phaser.Sprite { @@ -197,6 +205,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 +217,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 +505,14 @@ class GameLogic { } } + openDoor(doorname) { + 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)) { @@ -534,6 +552,7 @@ class GamePlay extends Phaser.State { game.world.setBounds(0, 0, 800, 600); game.stage.backgroundColor = '#000000'; game.physics.startSystem(Phaser.Physics.ARCADE); + console.log("Debug enabled:", !game.debug.isDisabled); var map = game.add.tilemap('gamemap'); map.addTilesetImage('tileset', 'tileset'); @@ -560,6 +579,7 @@ class GamePlay extends Phaser.State { game.physics.arcade.collide(logic.player, this.layer_walls); game.physics.arcade.collide(logic.player, this.layer_furniture); + game.physics.arcade.collide(logic.player, logic.doors); logic.update(); }