Update player's hitbox after shapeshifting
[shapeshift.git] / shapeshift.js
index e59f65c5a3d474c696bd65a379682a7e2089a131..d960d62ad4066ca11756ea3b8a3bf251b63b65da 100644 (file)
@@ -1,6 +1,7 @@
     window.onload = function() {
 
         var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
+        var ground;
         var platforms;
         var guards;
         var guard1, guard2;
@@ -90,7 +91,7 @@
             platforms.enableBody = true;
 
 
-            var ground = game.add.tileSprite(0, game.world.height - 80, game.world.width, 200, 'ground');
+            ground = game.add.tileSprite(0, game.world.height - 80, game.world.width, 200, 'ground');
             platforms.add(ground);
             ground.body.immovable = true;
 
                     player.shape = SHAPE_GIRL;
                     player.loadTexture('player_girl');
                 }
+
+                player.body.setSize(player.texture.width, player.texture.height);
+                if ((ground.y - player.y) < player.body.halfHeight)
+                    player.y = ground.y - player.body.halfHeight;
+
                 lastkeytime = game.time.now;
             }