Resize tilemap
[wgj58.git] / wgj58.js
index 8fe220f63a39ac710d93b8402fe35192e682dfe9..459b8c64ae4a6a9b8d426e8e0fd1899244910515 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,12 +55,30 @@ 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);
+       }
+
+       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() {
@@ -75,6 +94,10 @@ class Door extends Phaser.TileSprite {
                        this.isOpen = false;
                }
        }
+
+       update() {
+               game.debug.body(this);
+       }
 }
 
 class Player extends Phaser.Sprite {
@@ -212,7 +235,6 @@ 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:
@@ -501,7 +523,6 @@ class GameLogic {
        }
 
        openDoor(doorname) {
-               console.log("Opening doors.");
                this.doors.children.forEach(function(o) { if (o.name == doorname) o.open(); });
        }
 
@@ -548,6 +569,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');
@@ -574,6 +596,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();
 
        }