Fix door body
authorMegaBrutal <code+git@megabrutal.com>
Tue, 11 Sep 2018 22:40:00 +0000 (00:40 +0200)
committerMegaBrutal <code+git@megabrutal.com>
Tue, 11 Sep 2018 22:40:00 +0000 (00:40 +0200)
modified:   wgj58.js

wgj58.js

index fcfa0f408c164a3c93d727d140415489ed860db5..8885d24f3092fd3fbd9562f532c968cddae8070c 100644 (file)
--- a/wgj58.js
+++ b/wgj58.js
@@ -43,6 +43,7 @@ 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);
@@ -54,6 +55,7 @@ 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);
                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);
@@ -61,6 +63,22 @@ class Door extends Phaser.TileSprite {
                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() {