}
class Door extends Phaser.TileSprite {
- constructor(x, y, name, vector, longpanel) {
+ constructor(x, y, name, rotation, vector, longpanel) {
super(game, x, y, 64, 64, 'objects');
- this.tilePosition = new Phaser.Point(-64, -64);
- console.log("New door:", this);
+ this.name = name;
+ this.longpanel = longpanel;
+ if (!longpanel) {
+ this.anchor = new Phaser.Point(0.5, 0.5);
+ this.tilePosition = new Phaser.Point(-64, -64);
+ this.openvector = Phaser.Point.multiply(vector, new Phaser.Point(56, 56));
+ }
+ else {
+ this.width *= 2;
+ this.anchor = new Phaser.Point(0.75, 0.5);
+ 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);
+ 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);
+ }
+
+ 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.isOpen = true;
+ }
+ }
+
+ close() {
+ if (this.isOpen) {
+ this.closetween.start();
+ this.isOpen = false;
+ }
+ }
+
+ update() {
+ game.debug.body(this);
}
}
{ 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?" },
}
createDoor(object) {
+ /* Calculate movement vector and correct position (32 = half tile width/height). */
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;
+ case 0: vector = new Phaser.Point( -1, 0); object.x += 32; object.y -= 32; break;
+ case 90: vector = new Phaser.Point( 0, -1); object.x += 32; object.y += 32; break;
+ case 180: vector = new Phaser.Point( 1, 0); object.x -= 32; object.y += 32; break;
+ case 270: vector = new Phaser.Point( 0, 1); object.x -= 32; object.y -= 32; break;
default: console.error("Invalid rotation:", object.rotation);
}
- this.doors.add(new Door(object.x, object.y, object.name, vector, object.properties.longpanel));
+ this.doors.add(new Door(object.x, object.y, object.name, object.rotation, vector, object.properties.longpanel));
}
callMenu(menuitem) {
}
}
+ 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)) {
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');
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();
}