Add collision to doors
authorMegaBrutal <code+git@megabrutal.com>
Tue, 11 Sep 2018 06:30:30 +0000 (08:30 +0200)
committerMegaBrutal <code+git@megabrutal.com>
Tue, 11 Sep 2018 06:30:30 +0000 (08:30 +0200)
Enabled physics & collision on doors, however the bodies are off
due to the rotations, so it needs a fix.

modified:   wgj58.js

wgj58.js

index 8fe220f..fcfa0f4 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();
 
        }