X-Git-Url: http://git.megabrutal.com/?p=wgj58.git;a=blobdiff_plain;f=wgj58.js;h=49ebc06791d9c18e20abf986c5f81ec8308efa1c;hp=988d662e13d7a2fbfaa8d7f2f18e134d20bb7714;hb=2fbc55005177e795f983ef8aa8d30b6ca99f5751;hpb=cb29becc715c01e495228174666fdd66a64ad7ac diff --git a/wgj58.js b/wgj58.js index 988d662..49ebc06 100644 --- a/wgj58.js +++ b/wgj58.js @@ -42,6 +42,8 @@ class Dialogue { class Door extends Phaser.TileSprite { constructor(x, y, name, rotation, vector, longpanel) { super(game, x, y, 64, 64, 'objects'); + this.name = name; + this.longpanel = longpanel; if (!longpanel) { this.anchor = new Phaser.Point(0.5, 0.5); this.tilePosition = new Phaser.Point(-64, -64); @@ -53,25 +55,49 @@ class Door extends Phaser.TileSprite { this.tilePosition = new Phaser.Point(0, -64); this.openvector = Phaser.Point.multiply(vector, new Phaser.Point(116, 116)); } + if (rotation === undefined) rotation = 0; 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; + this.setBody(rotation); } - update() { - if ((this.opentween) && (game.time.now > 5000)) { - console.log(game.time.now, "Opening door."); + setBody(rotation) { + switch(rotation) { + case 0: + case 180: + this.body.setSize(this.width, 10, this.longpanel * (rotation / 180) * 64, 27); + break; + case 90: + case 270: + this.body.setSize(10, this.width, 27 + (this.longpanel * 64), this.longpanel * ((rotation - 270) / 180) * 64); + break; + default: + console.log("Unable to set body due to unknown rotation:", rotation); + } + } + + 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 +223,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?" }, @@ -250,6 +277,13 @@ class NPC_Clara extends GameNPC { } } +class NPC_Carlos extends GameNPC { + actionTalk() { + super.actionTalk(); + logic.endTalk(); + } +} + class GameInterface extends Phaser.Group { constructor(game, parent) { @@ -442,6 +476,10 @@ class GameLogic { newChar = new NPC_Clara(object.x, object.y, 'clara', "Clara", "Clara Tnavelerri", 200); this.clara = newChar; break; + case 'carlos': + newChar = new NPC_Carlos(object.x, object.y, 'carlos', "Carlos", "Carlos Elbacalper", 150); + this.carlos = newChar; + break; default: console.error("Unknown character:", object); } @@ -495,6 +533,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)) { @@ -522,6 +568,7 @@ class GamePlay extends Phaser.State { game.load.image('player', 'john.png'); game.load.image('clara', 'clara.png'); + game.load.image('carlos', 'carlos.png'); game.load.image('saiki', 'saiki.png'); game.load.image('tileset', 'tileset.png'); game.load.image('objects', 'objects.png'); @@ -534,6 +581,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 +608,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(); }