}
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);
+ 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));
+ }
+ 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);
+ }
+
+ update() {
+ if ((this.opentween) && (game.time.now > 5000)) {
+ console.log(game.time.now, "Opening door.");
+ this.opentween.start();
+ this.opentween = null;
+ }
+ else if ((this.closetween) && (game.time.now > 10000)) {
+ console.log(game.time.now, "Closing door.");
+ this.closetween.start();
+ this.closetween = null;
+ }
}
}
}
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) {