Add collision to doors
[wgj58.git] / wgj58.js
index 8fe220f63a39ac710d93b8402fe35192e682dfe9..fcfa0f408c164a3c93d727d140415489ed860db5 100644 (file)
--- a/wgj58.js
+++ b/wgj58.js
@@ -55,11 +55,12 @@ class Door extends Phaser.TileSprite {
                        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);
                this.isOpen = false;
+               game.physics.arcade.enable(this);
+               this.body.immovable = true;
        }
 
        open() {
@@ -75,6 +76,10 @@ class Door extends Phaser.TileSprite {
                        this.isOpen = false;
                }
        }
+
+       update() {
+               game.debug.body(this);
+       }
 }
 
 class Player extends Phaser.Sprite {
@@ -501,7 +506,6 @@ class GameLogic {
        }
 
        openDoor(doorname) {
-               console.log("Opening doors.");
                this.doors.children.forEach(function(o) { if (o.name == doorname) o.open(); });
        }
 
@@ -548,6 +552,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 +579,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();
 
        }